File tree 1 file changed +13
-1
lines changed
packages/@sanity/client/src/assets
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -12,12 +12,24 @@ function toPromise(observable) {
12
12
. toPromise ( )
13
13
}
14
14
15
+ function optionsFromFile ( opts , file ) {
16
+ if ( typeof window === 'undefined' || ! ( file instanceof window . File ) ) {
17
+ return opts
18
+ }
19
+
20
+ return assign ( {
21
+ filename : opts . preserveFilename === false ? undefined : file . name ,
22
+ contentType : file . type
23
+ } , opts )
24
+ }
25
+
15
26
assign ( AssetsClient . prototype , {
16
- upload ( assetType , body , options = { } ) {
27
+ upload ( assetType , body , opts = { } ) {
17
28
validators . validateAssetType ( assetType )
18
29
19
30
const dataset = validators . hasDataset ( this . client . clientConfig )
20
31
const assetEndpoint = assetType === 'image' ? 'images' : 'files'
32
+ const options = optionsFromFile ( opts , body )
21
33
const { id, label, filename, meta} = options
22
34
const query = { id, label, filename, meta}
23
35
You can’t perform that action at this time.
0 commit comments