Skip to content

Commit 53ab65d

Browse files
committed
AV.File: 支持在构造参数的 data 参数中提供 owner
1 parent e4615ef commit 53ab65d

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/file.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,20 @@ module.exports = function(AV) {
342342
// 用来存储转换后要上传的 base64 String
343343
this._base64 = '';
344344

345-
var currentUser;
346-
try {
347-
currentUser = AV.User.current();
348-
}
349-
catch (e) {
350-
console.warn('Get current user failed. It seems this runtime use an async storage system, please new AV.File in the callback of AV.User.currentAsync().');
345+
let owner;
346+
347+
if (data && data.owner) {
348+
owner = data.owner;
349+
} else {
350+
try {
351+
owner = AV.User.current();
352+
} catch (e) {
353+
console.warn('Get current user failed. It seems this runtime use an async storage system, please new AV.File in the callback of AV.User.currentAsync().');
354+
}
351355
}
356+
352357
this._metaData = {
353-
owner: (currentUser ? currentUser.id : 'unknown')
358+
owner: (owner ? owner.id : 'unknown')
354359
};
355360

356361
// Guess the content type from the extension if we need to.

0 commit comments

Comments
 (0)