Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial work on File and Array<File> support #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Copy link

Choose a reason for hiding this comment

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

indentation is off here

if (this.isArrayOfFiles(request.variables[key])) {
return true;
Copy link

Choose a reason for hiding this comment

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

The rest of this file doesn't use semicolons, probably following Standard Style

}
}
}
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
Copy link

Choose a reason for hiding this comment

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

return here will cause only the first file to get appended

}
} else {
variables[key] = v
}
Expand Down