Use new sftp service image without multipart file upload
This commit is contained in:
@@ -67,14 +67,43 @@ export function createDirectoryModel(origin, accessToken, api) {
|
||||
|
||||
return result.body.entries;
|
||||
},
|
||||
upload(targetDir, file, progressHandler) {
|
||||
async upload(targetDir, file, progressHandler) {
|
||||
// file may contain a file name or a file path + file name
|
||||
const relativefilePath = (file.webkitRelativePath ? file.webkitRelativePath : file.name);
|
||||
|
||||
return superagent.post(`${origin}/api/v1/${api}/files/${encodeURIComponent(sanitize(targetDir + '/' + relativefilePath))}`)
|
||||
.query({ access_token: accessToken })
|
||||
.attach('file', file)
|
||||
.on('progress', progressHandler);
|
||||
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.upload.addEventListener('progress', (event) => {
|
||||
if (event.loaded) progressHandler({ direction: 'upload', loaded: event.loaded});
|
||||
});
|
||||
|
||||
xhr.open('POST', `${origin}/api/v1/${api}/files/${encodeURIComponent(sanitize(targetDir + '/' + relativefilePath))}?access_token=${accessToken}`);
|
||||
|
||||
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
|
||||
xhr.setRequestHeader('Content-Length', file.size);
|
||||
|
||||
xhr.send(file);
|
||||
});
|
||||
|
||||
console.log('was passiert?')
|
||||
const res = await req;
|
||||
},
|
||||
async newFile(folderPath, fileName) {
|
||||
await superagent.post(`${origin}/api/v1/${api}/files/${folderPath}`)
|
||||
@@ -82,9 +111,7 @@ export function createDirectoryModel(origin, accessToken, api) {
|
||||
.attach('file', new File([], fileName));
|
||||
},
|
||||
async newFolder(folderPath) {
|
||||
await superagent.post(`${origin}/api/v1/${api}/files/${folderPath}`)
|
||||
.query({ access_token: accessToken })
|
||||
.send({ directory: true });
|
||||
await superagent.post(`${origin}/api/v1/${api}/files/${folderPath}?access_token=${accessToken}&directory=true`);
|
||||
},
|
||||
async remove(filePath) {
|
||||
await superagent.del(`${origin}/api/v1/${api}/files/${filePath}`)
|
||||
|
||||
Reference in New Issue
Block a user