f-miyu / Plugin.FirebaseStorage

MIT License
12 stars 7 forks source link

OOM exception when uploading big files using stream #3

Open guillermo-gerard opened 4 years ago

guillermo-gerard commented 4 years ago

Hi f-miyu: I've taken a look at your implementation of the PutStreamAsync method: you are only converting the given stream to a byte array and then you are uploading them using PutBytesAsync. The thing is that you are using memoryStream.ToArray() which in turn is trying to allocate a huge array if the file to be uploaded is big (and, if you think in media files, it is big almost all the time).

Just wanted you to know that this is happening and it is a common issue

In addition, a suggestion: why not adding a new method to upload a file by providing a the file Uri? That will be useful for gallery and content:// files if you don't want to copy it to a file to get the path (or there is a way to do it without making a copy? I didn't find a way yet)