@@ -6,8 +6,11 @@ import * as cosmos from './cosmos'
66import * as substrate from './substrate'
77import * as solana from './solana'
88import * as avalanche from './avalanche'
9+ import FormDataNode from 'form-data'
910const shajs = require ( 'sha.js' )
1011
12+ const isBrowser = typeof FormData !== 'undefined'
13+
1114export async function put_content (
1215 message , content , inline_requested , storage_engine , api_server ) {
1316
@@ -66,8 +69,14 @@ export async function storage_push (
6669
6770export async function ipfs_push_file (
6871 fileobject , { api_server = DEFAULT_SERVER } = { } ) {
69- let formData = new FormData ( )
70- formData . append ( 'file' , fileobject )
72+ let formData = null
73+ if ( isBrowser ) {
74+ formData = new FormData ( )
75+ formData . append ( 'file' , fileobject )
76+ } else {
77+ formData = new FormDataNode ( )
78+ formData . append ( 'file' , fileobject , 'random.txt' ) // FileName is required but does not seem to have any effect
79+ }
7180
7281 let response = await axios . post ( `${ api_server } /api/v0/ipfs/add_file` ,
7382 formData ,
@@ -87,8 +96,14 @@ export async function ipfs_push_file (
8796
8897export async function storage_push_file (
8998 fileobject , { api_server = DEFAULT_SERVER } = { } ) {
90- let formData = new FormData ( )
91- formData . append ( 'file' , fileobject )
99+ let formData = null
100+ if ( isBrowser ) {
101+ formData = new FormData ( )
102+ formData . append ( 'file' , fileobject )
103+ } else {
104+ formData = new FormDataNode ( )
105+ formData . append ( 'file' , fileobject , 'random.txt' ) // FileName is required but does not seem to have any effect
106+ }
92107
93108 let response = await axios . post ( `${ api_server } /api/v0/storage/add_file` ,
94109 formData ,
0 commit comments