Skip to content

Commit ead0d9d

Browse files
authored
fix: set URL attribute after upload succeed (#640)
1 parent bf66cb3 commit ead0d9d

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/uploader/cos.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ const { getAdapter } = require('../adapter');
22
const debug = require('debug')('cos');
33

44
module.exports = function(uploadInfo, data, file, saveOptions = {}) {
5-
file.attributes.url = uploadInfo.url;
6-
file._bucket = uploadInfo.bucket;
7-
file.id = uploadInfo.objectId;
85
const url =
96
uploadInfo.upload_url + '?sign=' + encodeURIComponent(uploadInfo.token);
107
const fileFormData = {
@@ -29,6 +26,9 @@ module.exports = function(uploadInfo, data, file, saveOptions = {}) {
2926
error.response = response;
3027
throw error;
3128
}
29+
file.attributes.url = uploadInfo.url;
30+
file._bucket = uploadInfo.bucket;
31+
file.id = uploadInfo.objectId;
3232
return file;
3333
},
3434
error => {

src/uploader/qiniu.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ const { getAdapter } = require('../adapter');
22
const debug = require('debug')('leancloud:qiniu');
33

44
module.exports = function(uploadInfo, data, file, saveOptions = {}) {
5-
file.attributes.url = uploadInfo.url;
6-
file._bucket = uploadInfo.bucket;
7-
file.id = uploadInfo.objectId;
85
// Get the uptoken to upload files to qiniu.
96
const uptoken = uploadInfo.token;
107
const url = uploadInfo.upload_url || 'https://upload.qiniup.com';
@@ -40,6 +37,9 @@ module.exports = function(uploadInfo, data, file, saveOptions = {}) {
4037
error.response = response;
4138
throw error;
4239
}
40+
file.attributes.url = uploadInfo.url;
41+
file._bucket = uploadInfo.bucket;
42+
file.id = uploadInfo.objectId;
4343
return file;
4444
},
4545
error => {

src/uploader/s3.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ const _ = require('underscore');
22
const ajax = require('../utils/ajax');
33

44
module.exports = function upload(uploadInfo, data, file, saveOptions = {}) {
5-
file.attributes.url = uploadInfo.url;
6-
file._bucket = uploadInfo.bucket;
7-
file.id = uploadInfo.objectId;
8-
95
/* NODE-ONLY:start */
106
if (data instanceof require('stream')) {
117
// data.pipe(req);
@@ -27,5 +23,10 @@ module.exports = function upload(uploadInfo, data, file, saveOptions = {}) {
2723
file._uploadHeaders
2824
),
2925
onprogress: saveOptions.onprogress,
30-
}).then(() => file);
26+
}).then(() => {
27+
file.attributes.url = uploadInfo.url;
28+
file._bucket = uploadInfo.bucket;
29+
file.id = uploadInfo.objectId;
30+
return file;
31+
});
3132
};

0 commit comments

Comments
 (0)