Having a hard time with UAPI Functions - Fileman::upload_files
This is on front-end:
(...)
zip.generateAsync({type:"blob"}).then(async function(content) {
(...)
formData.append('my.zip', content);
const response = await api.post('/ul', formData);
(...)
}
This is on Node.js + express:
(...)
const zip = req.files['my.zip'].data
If I console.log(req.files['my.zip'])
{
name: 'blob',
data: <Buffer 50 4b 03 04 0a 00 00 00 00 00 0d 6d 48 55 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 6a 73 2f 50 4b 03 04 0a 00 00 00 00 00 0d 6d 48 55 00 00 00 ... 14279 more bytes>,
size: 14329,
encoding: '7bit',
tempFilePath: '',
truncated: false,
mimetype: 'application/zip',
md5: '3dccb4836924bcafa1a6a642ffa227b2',
mv: [Function: mv]
}
<Buffer 48 69 2c 20 4a 6f 75 72 6e 61 6c 44 45 56 20 55 73 65 72 73 2e 20 54 68 61 6e 6b 20 59 6f 75 2e>
If I console.log(zip):
<Buffer 50 4b 03 04 0a 00 00 00 00 00 c9 6c 48 55 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 6a 73 2f 50 4b 03 04 0a 00 00 00 00 00 c9 6c 48 55 00 00 00 ... 14279 more bytes>
<Buffer 48 69 2c 20 4a 6f 75 72 6e 61 6c 44 45 56 20 55 73 65 72 73 2e 20 54 68 61 6e 6b 20 59 6f 75 2e>
Then:
(...)
const form = new FormData();
form.append('dir', dir);
form.append('overwrite', 1);
form.append('file-1', zip, 'my.zip');
axios.post(url,
form,
{
headers: {
...form.getHeaders(),
'Authorization': accessToken
}
}).then(function (response) {
console.log('axios')
console.log(response.data);
}).catch(function(response){
console.log(response);
});
response.data is:
{
warnings: null,
status: 0,
errors: [ 'You must specify at least one file to upload.' ],
data: { warned: 0, uploads: [], succeeded: 0, failed: 0 },
messages: null,
metadata: {}
}
I tried every possible way. It always returns this "You must specify at least one file to upload".
What am I doing wrong here?
This is on front-end:
(...)
zip.generateAsync({type:"blob"}).then(async function(content) {
(...)
formData.append('my.zip', content);
const response = await api.post('/ul', formData);
(...)
}
This is on Node.js + express:
(...)
const zip = req.files['my.zip'].data
If I console.log(req.files['my.zip'])
{
name: 'blob',
data: <Buffer 50 4b 03 04 0a 00 00 00 00 00 0d 6d 48 55 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 6a 73 2f 50 4b 03 04 0a 00 00 00 00 00 0d 6d 48 55 00 00 00 ... 14279 more bytes>,
size: 14329,
encoding: '7bit',
tempFilePath: '',
truncated: false,
mimetype: 'application/zip',
md5: '3dccb4836924bcafa1a6a642ffa227b2',
mv: [Function: mv]
}
<Buffer 48 69 2c 20 4a 6f 75 72 6e 61 6c 44 45 56 20 55 73 65 72 73 2e 20 54 68 61 6e 6b 20 59 6f 75 2e>
If I console.log(zip):
<Buffer 50 4b 03 04 0a 00 00 00 00 00 c9 6c 48 55 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 6a 73 2f 50 4b 03 04 0a 00 00 00 00 00 c9 6c 48 55 00 00 00 ... 14279 more bytes>
<Buffer 48 69 2c 20 4a 6f 75 72 6e 61 6c 44 45 56 20 55 73 65 72 73 2e 20 54 68 61 6e 6b 20 59 6f 75 2e>
Then:
(...)
const form = new FormData();
form.append('dir', dir);
form.append('overwrite', 1);
form.append('file-1', zip, 'my.zip');
axios.post(url,
form,
{
headers: {
...form.getHeaders(),
'Authorization': accessToken
}
}).then(function (response) {
console.log('axios')
console.log(response.data);
}).catch(function(response){
console.log(response);
});
response.data is:
{
warnings: null,
status: 0,
errors: [ 'You must specify at least one file to upload.' ],
data: { warned: 0, uploads: [], succeeded: 0, failed: 0 },
messages: null,
metadata: {}
}
I tried every possible way. It always returns this "You must specify at least one file to upload".
What am I doing wrong here?