@@ -6,8 +6,11 @@ import * as cosmos from './cosmos'
6
6
import * as substrate from './substrate'
7
7
import * as solana from './solana'
8
8
import * as avalanche from './avalanche'
9
+ import FormDataNode from 'form-data'
9
10
const shajs = require ( 'sha.js' )
10
11
12
+ const isBrowser = typeof FormData !== 'undefined'
13
+
11
14
export async function put_content (
12
15
message , content , inline_requested , storage_engine , api_server ) {
13
16
@@ -66,8 +69,14 @@ export async function storage_push (
66
69
67
70
export async function ipfs_push_file (
68
71
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
+ }
71
80
72
81
let response = await axios . post ( `${ api_server } /api/v0/ipfs/add_file` ,
73
82
formData ,
@@ -87,8 +96,14 @@ export async function ipfs_push_file (
87
96
88
97
export async function storage_push_file (
89
98
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
+ }
92
107
93
108
let response = await axios . post ( `${ api_server } /api/v0/storage/add_file` ,
94
109
formData ,
0 commit comments