我需要将文件上传到后端,并且尝试了以下两种方法:
let formData = new FormData();
formData.append(path, file, path+'.mp3');
fetch("https://api.backendless.com/E66CB437-EB54-734A-FF68-4D89CAEBFD00/D38A1511-013A-AF1B-FF23-A015C6A0B600/files/recordings/ ", {
method: 'POST',
body: formData
}).then(res => res.json())
.then(response => console.log('Success:', JSON.stringify(response)))
.catch(error => console.error('Error:', error));
我也尝试使用无后端JS API:
Backendless.Files.upload( file, 'recordings' ).then( function( fileURL ) {
console.log(fileURL);
Backendless.Persistence.of("RecordingsFile").save({File:fileURL}).then((fileEntry)=>{
//Make relation to created recording
Backendless.Persistence.of("RecordingsFile").setRelation( fileEntry, 'recordings:Recordings:1', [saved] );
})
}).catch( function( error ) {
console.log(error)
});
两个都无法工作并引发此错误:
Success: {"code":6011,"message":"Corrupted multipart request. File content is absent in request body","errorData":{}}
我知道文件不是未定义的,因为我在请求之前将其打印并获得文件Object输出。我还尝试过在代码中创建文件对象,但毫无用处。
感谢您的帮助!埃德。