frontend: fix all usage of file upload without multipart
This commit is contained in:
@@ -104,10 +104,8 @@ export function createDirectoryModel(origin, accessToken, api) {
|
||||
|
||||
const res = await req;
|
||||
},
|
||||
async newFile(folderPath, fileName) {
|
||||
await superagent.post(`${origin}/api/v1/${api}/files/${folderPath}`)
|
||||
.query({ access_token: accessToken })
|
||||
.attach('file', new File([], fileName));
|
||||
async newFile(filePath) {
|
||||
await this.save(filePath, '')
|
||||
},
|
||||
async newFolder(folderPath) {
|
||||
await superagent.post(`${origin}/api/v1/${api}/files/${folderPath}?access_token=${accessToken}&directory=true`);
|
||||
@@ -141,10 +139,36 @@ export function createDirectoryModel(origin, accessToken, api) {
|
||||
},
|
||||
async save(filePath, content) {
|
||||
const file = new File([content], 'file');
|
||||
await superagent.post(`${origin}/api/v1/${api}/files/${filePath}`)
|
||||
.query({ access_token: accessToken })
|
||||
.attach('file', file)
|
||||
.field('overwrite', 'true');
|
||||
|
||||
const req = new Promise(function (resolve, reject) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.addEventListener('load', () => {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
resolve(xhr.response);
|
||||
} else {
|
||||
reject({
|
||||
status: xhr.status,
|
||||
statusText: xhr.statusText
|
||||
});
|
||||
}
|
||||
});
|
||||
xhr.addEventListener('error', () => {
|
||||
reject({
|
||||
status: xhr.status,
|
||||
statusText: xhr.statusText
|
||||
});
|
||||
});
|
||||
|
||||
xhr.open('POST', `${origin}/api/v1/${api}/files/${filePath}?access_token=${accessToken}&overwrite=true`);
|
||||
|
||||
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
|
||||
xhr.setRequestHeader('Content-Length', file.size);
|
||||
|
||||
xhr.send(file);
|
||||
});
|
||||
|
||||
const res = await req;
|
||||
},
|
||||
async getFile(path) {
|
||||
let result;
|
||||
|
||||
Reference in New Issue
Block a user