SkygearIO / skygear-SDK-Android

Skygear Android SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support upload asset with large file size

Steven-Chan opened this issue · comments

The sdk is using volley multipart to upload file, which does not handle large file well. See google/volley#106.

But the sdk can still handle large file better. Currently, an Asset object only accepts byte[] in constructor, which force developer to put the whole file data in memory.

To solve this problem, Asset should also accept being constructed with input stream / uri with a content resolver.

Case 1: byte[]

  • Asset size = length of the byte array
  • When upload,
    • write the byte array to a temporary file
    • add the file to the multipart request

Case 2: InputStream

  • Asset size = given when the Asset object is constructed
  • When upload,
    • pipe the data from input stream to a temporary file <- unless volley support piping it to the request directly
    • add the file to the multipart request

Case 3: Uri with ContentResolver

Get a InputStream using the uri and content resolver when needed.


Update:

InputStream is too low level and we need file size when save asset which is not provided by the stream, we may support Uri (or maybe File and URL later).