Skip to content

Commit 998a05d

Browse files
authored
[client] Retrieve original filename and content type from File instances (#154)
1 parent fd34fd5 commit 998a05d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/@sanity/client/src/assets/assetsClient.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,24 @@ function toPromise(observable) {
1212
.toPromise()
1313
}
1414

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+
1526
assign(AssetsClient.prototype, {
16-
upload(assetType, body, options = {}) {
27+
upload(assetType, body, opts = {}) {
1728
validators.validateAssetType(assetType)
1829

1930
const dataset = validators.hasDataset(this.client.clientConfig)
2031
const assetEndpoint = assetType === 'image' ? 'images' : 'files'
32+
const options = optionsFromFile(opts, body)
2133
const {id, label, filename, meta} = options
2234
const query = {id, label, filename, meta}
2335

0 commit comments

Comments
 (0)