Skip to content

Commit

Permalink
Initial work on File and Array<File> support
Browse files Browse the repository at this point in the history
Also see issue HriBB#3
  • Loading branch information
sandervanhooft authored Dec 7, 2016
1 parent 27b866b commit 29028f7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/UploadNetworkInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,34 @@ export class UploadNetworkInterface extends HTTPFetchNetworkInterface {
: this.getJSONOptions(req)
return fetch(this._uri, options);
}

isArrayOfFiles(list) {
if (Array.isArray(list)) {
let returnValue = false;
for (var key in list) {
if (list[key] instanceof File) {
returnValue = true;
} else {
return false;
}
}
return returnValue
}
return false;
}

isUpload({ request }) {
if (request.variables) {
for (let key in request.variables) {
if (request.variables[key] instanceof FileList) {
return true
}
if (request.variables[key] instanceof File) {
return true;
}
if (this.isArrayOfFiles(request.variables[key])) {
return true;
}
}
}
return false
Expand All @@ -46,6 +67,10 @@ export class UploadNetworkInterface extends HTTPFetchNetworkInterface {
let v = request.variables[key]
if (v instanceof FileList) {
Array.from(v).forEach(f => body.append(key, f))
} else if (isArrayOfFiles(v)) {
for (var file in v) {
return body.append(key, file); // this part seems buggy
}
} else {
variables[key] = v
}
Expand Down

1 comment on commit 29028f7

@sandervanhooft
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thebigredgeek I believe lines 70-73 are causing some trouble. Do you have a suggestion?

Please sign in to comment.