roopakv / google-photos

Library to make hitting the Google Photos api easy
MIT License
56 stars 22 forks source link

Remove 50 item limit from uploadMultiple #16

Closed mcpengelly closed 4 years ago

mcpengelly commented 5 years ago

Motivation

The :batchCreate api which is used by uploadMultiple() only supports a maximum of 50 media items per request as per the warning on this page and the following error response message when using the api:

Error: StatusCodeError: 400 - {"error":{"code":400,"message":"Request must have less than 50 items.","status":"INVALID_ARGUMENT"}}

To work around this I capped mediaItems at 50 items per :batchCreate call and iteratively call :batchCreate until the list of images is exhausted. This allows users to input any amount of images for upload.

Manual Testing

I tested this with a sample of 2500 images works as intended. Although the timeout im forced to use right now slows the uploads down significantly, it does a maximum of 5 uploads/second right now due to the timeout alone. I was able to upload 2500 images to a google album with these changes in ~750 seconds.

caveats

more...

roopakv commented 4 years ago

Thank you for the PR. I will take a look tomorrow evening or saturday morning worst case :) sorry for the delays.

mcpengelly commented 4 years ago

No worries at all @roopakv I expect you're busy! I just like to keep PRs as an ongoing process so you (or anyone) can leave feedback whenever they have a chance. If it seems like i'm impatient thats not the case!

roopakv commented 4 years ago

thank you for the PR!

thoughts

LGTM otherwise

mcpengelly commented 4 years ago

love the auto chunking and spreading over time. in the future we could make that number customizeable instead of 10000 so that people can tune as needed

I like this. A default value that is the bare minimum would work and open up more flexibility if the users the google app is somehow able to get more then 500-600 requests per minute (ie if theyre a google partner)

lets use lodash.chunk

sounds good

mcpengelly commented 4 years ago

should be good now, addressed feedback and gave it another test with 150 images and it seemed to go fine! I should really have provided a test case or something though