Skip to content

Uploading large file as base64 string to parse server throws an error #1516

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

Closed
4 tasks done
samateja opened this issue Jul 25, 2022 · 5 comments
Closed
4 tasks done
Labels
type:question Support or code-level question

Comments

@samateja
Copy link

New Issue Checklist

Issue Description

Uploading an recorded video of 17mb from ionic android to parse server throws an error.

Steps to reproduce

  • Ionic media capture record 5 or 10 or 30 seconds video
  • convert to base64 - which gives 17mb of string
  • create parse.save('filename', {base64: base64data});

-- Which throws an error at RegExp.test().

Looking for help.

Actual Outcome

Expecting to upload video same as image

Expected Outcome

Expecting to upload video same as image

Environment

version --- "^3.4.3",

Server

  • Parse Server version: "^5.0.0-beta.6",
  • Operating system: Windows
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Local

Database

  • System (MongoDB or Postgres): Mongo DB
  • Database version: 1.31.3
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): Local

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): Ionic Angular
  • SDK version: android
@parse-github-assistant
Copy link

parse-github-assistant bot commented Jul 25, 2022

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@mtrezza
Copy link
Member

mtrezza commented Jul 25, 2022

which gives 17mb of string

This seems to be an unusual approach to handle a file of that size. Storing 17 MB of string in a variable in memory is not the most robust concept. You may be hitting a memory limit with regex there. More investigation on your side would be needed to identify the root cause; find out where the error occurs - in the Parse client SDK or in Parse Server and at which line of code.

General note; please do not post the same question multiple times; you (and someone else with a different account) has been posting this issue in multiple places over the last 24 hours.

@mtrezza mtrezza added the type:question Support or code-level question label Jul 25, 2022
@mtrezza mtrezza changed the title Uploading an recorded video of 17mb from ionic android to parse server throws an error. Uploading large file to parse server throws an error Jul 25, 2022
@mtrezza mtrezza changed the title Uploading large file to parse server throws an error Uploading large file as base64 string to parse server throws an error Jul 25, 2022
@FransGH
Copy link

FransGH commented Aug 17, 2022

Just stumbled over a similar issue in the JS SDK. Maybe this approach has now been added to other Parse SDK's as well. We suddenly got this error in one of our automated tests after years of not having any issue:

"Cannot create a Parse.File without valid data URIs or base64 encoded data."

As a fix, we modified some older code to pass a byte array instead (which makes more sense).

It took however some time to figure out what was happening here. Turns out Parse JS-SDK 3.3.4 over 3.3.0 has a (breaking?) change that is not immediately obvious until looking at the Parse.File source code.

In 3.3.4, this code is executed in Parse.File() to verify the base64 encoded file data:

        // Check if data URI or base64 string is valid
        const validationRegex = new RegExp(base64Regex.source + '|' + dataUriRegex.source, 'i');

And here the regex:

const base64Regex = new RegExp('([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))', 'i');
const dataUriRegex = new RegExp(`^data:([a-zA-Z]+\\/[-a-zA-Z0-9+.]+(;[a-z-]+=[a-zA-Z0-9+.-]+)?)?(;base64)?,(${base64Regex.source})*$`, 'i');

With a ~2MB base64 string (jpeg image) it took around 6 minutes (!!!) with 100% cpu (=full single core) until the regex failed. The base64 was however correct as any image saved with Parse JS-SDK 3.3.0 and earlier could be downloaded/viewed without error.

IF there is a need to test for valid base64 data in Parse.File, a simple base64 decode would probably be more efficient (at the expense of using more memory).

But I would question that there is a need to test at all. Worse case the base64 data is invalid and either:

  • save/upload fails (?)
  • the storage adapter fails (?)
  • a client reading it fails (most definately)

The 1st two can be caught by the client-app while uploading.
The last one can also happen with pure binary data and is the client-app responsibility to catch, not the Parse SDK.

Just wanted to quickly comment on this so others might save some time troubleshooting. Problem is solved on my end and won't be using base64 upload anymore.

@mtrezza mtrezza closed this as completed Aug 18, 2022
@mtrezza
Copy link
Member

mtrezza commented Aug 18, 2022

@FransGH Please take a look at #1510 as your issue may be a duplicate. If it's not could you please open a new issue to discuss this properly?

Closing this issue because of inactivity and no further feedback from OP.

@FransGH
Copy link

FransGH commented Aug 18, 2022

See #1532

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

3 participants