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

Add support for uploading blob item's data #254

Merged
merged 3 commits into from
Jul 27, 2018

Conversation

MikeTschudi
Copy link
Member

For reasonable browsers, a Blob can be converted into a File and sent up with its filename. For IE 11 & Edge, the File constructor is not available, and even if one adds the missing File properties to the Blob, it's sent up to AGOL as "blob" by these two browsers. Changing encode-form-data to use the filename in the FormData.append call gets past this behavior.

I changed the name of IItemJsonDataRequestOptions from a documentation perspective since it can be used by both the JSON and binary functions.

Working on test code.

@MikeTschudi MikeTschudi changed the title ⚠️ WIP: Add support for uploading blob item's data WIP: Add support for uploading blob item's data Jul 23, 2018
@@ -25,9 +25,9 @@ export interface IItemIdRequestOptions extends IUserRequestOptions {
owner?: string;
}

export interface IItemJsonDataRequestOptions extends IItemIdRequestOptions {
export interface IItemJsonRequestOptions extends IItemIdRequestOptions {
Copy link
Contributor

Choose a reason for hiding this comment

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

to convey that it supports both JSON object literals and blobs, would IItemDataRequestOptions be a better (re)name?

Copy link
Member Author

Choose a reason for hiding this comment

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

That was the intention--I erred.

*/
export function addItemBinaryData(
requestOptions: IItemJsonRequestOptions
): Promise<any> {
Copy link
Contributor

Choose a reason for hiding this comment

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

there is a lot of Promise<any> in this package, but since we know what the signature of the response will be, it'd be good to be explicit about what this method returns.

export function addItemBinaryData(
requestOptions: IItemJsonRequestOptions
): Promise<any> {
const owner = requestOptions.owner || requestOptions.authentication.username;
Copy link
Contributor

Choose a reason for hiding this comment

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

hot off the presses (in #252). you can now use determineOwner()

const owner = determineOwner(requestOptions);

requestOptions.params = {
...requestOptions.params,
file: requestOptions.data
};
Copy link
Contributor

@jgravois jgravois Jul 23, 2018

Choose a reason for hiding this comment

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

this is a nitpick, but i prefer to mixin user-supplied options after internal props are set.

it feels like a nice contract to explicitly prohibit overwriting what the developer passes in.

requestOptions.params = {
  file: requestOptions.data,
  ...requestOptions.params
};

@jgravois jgravois force-pushed the feat/binary-data branch 2 times, most recently from 8e357cb to be8628b Compare July 23, 2018 21:27
@coveralls
Copy link

coveralls commented Jul 23, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 39a0710 on feat/binary-data-upload into be8628b on feat/binary-data.

Copy link
Contributor

@jgravois jgravois left a comment

Choose a reason for hiding this comment

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

i just pushed up another commit with:

  • a couple naming tweaks
  • another test (to get coverage back to 100%)
  • two new interfaces for add/update methods to document the responses that will be returned by the server.

i'm scratching my head as to what in the hell is going on with JS Dates on the travis box right now. locally, its all 💚

new Date(2016,7,17).getTime()
> 1471392000000 // ????

edit:
i'm going to be out of the office 'til friday. hopefully this'll give @patrickarlt a chance to look at #251 on its own first. if he's happy with it, we'll merge both and ship.

@MikeTschudi
Copy link
Member Author

@jgravois thank you for the review and improvements. Travis date puzzled me; switched to constructing date from milliseconds to see if that will work both with npm test and Travis.

MikeTschudi added a commit that referenced this pull request Jul 24, 2018
@MikeTschudi
Copy link
Member Author

@jgravois would you please review the last two commits: changing the Date construction because of the Travis problem and adding a test for encode-form-data?

@jgravois
Copy link
Contributor

would you please review the last two commits

looks great! i'm going to try to merge/release today.

Copy link
Member

@tomwayson tomwayson left a comment

Choose a reason for hiding this comment

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

Other than the suggested name change this LGTM, thanks @MikeTschudi!

@@ -30,9 +30,9 @@ export interface IItemIdRequestOptions extends IUserRequestOptions {
owner?: string;
}

export interface IItemJsonDataRequestOptions extends IItemIdRequestOptions {
export interface IItemDataOptions extends IItemIdRequestOptions {
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest naming this IItemDataRequestOptions

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed. i introduced that typo during code review.

i'm going to rebase this branch to clean up the commit history and then merge.

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, just realized i already used IItemDataRequestOptions in #251.

my best suggestion for this one is IItemDataAddRequestOptions.

Copy link
Member

@tomwayson tomwayson Jul 27, 2018

Choose a reason for hiding this comment

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

Not to be that guy, but I would have gone w/ IItemAddDataRequestOptions

@jgravois jgravois changed the title WIP: Add support for uploading blob item's data Add support for uploading blob item's data Jul 27, 2018
jgravois and others added 3 commits July 27, 2018 14:14
AFFECTS PACKAGES:
@esri/arcgis-rest-items
…s of non-objects

Fixed addItemData input type and mix-in ordering #254

Switched to using determineOwner call #254

doc response, add another test

method and interface rename

whoops

Changed Date constructor to see if Travis behaves better #254

Added test for FormData path #254

one more interface name change
@jgravois jgravois closed this Jul 27, 2018
@jgravois jgravois reopened this Jul 27, 2018
@jgravois jgravois merged commit 41a540a into feat/binary-data Jul 27, 2018
@jgravois
Copy link
Contributor

🚀

@jgravois jgravois deleted the feat/binary-data-upload branch July 27, 2018 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants