Skip to content

Commit

Permalink
fix(item): use fileName parameter to name Blobs when present
Browse files Browse the repository at this point in the history
AFFECTS PACKAGES:
@esri/arcgis-rest-request
  • Loading branch information
jgravois committed Sep 19, 2018
1 parent d3f2553 commit 9f5c093
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/arcgis-rest-request/src/utils/encode-form-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ export function encodeFormData(params: any): FormData | string {
const formData = new FormData();
Object.keys(newParams).forEach((key: any) => {
if (typeof Blob !== "undefined" && newParams[key] instanceof Blob) {
// Pass on the explicit file name to override default name such as "blob"
formData.append(key, newParams[key], newParams[key].name || key);
/* To name the Blob:
1. look to an alternate request parameter called 'fileName'
2. see if 'name' has been tacked onto the Blob manually
3. if all else fails, use the request parameter
*/
const filename = newParams["fileName"] || newParams[key].name || key;
formData.append(key, newParams[key], filename);
} else {
formData.append(key, newParams[key]);
}
Expand Down
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"ordered-imports": ["any"],
"only-arrow-functions": [false],
"object-literal-sort-keys": false,
"interface-name": [true, "always-prefix"]
"interface-name": [true, "always-prefix"],
"no-string-literal": false
}
}

0 comments on commit 9f5c093

Please sign in to comment.