Skip to content

Possible Bug Creating New File #517

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
montymxb opened this issue Nov 29, 2017 · 2 comments
Closed

Possible Bug Creating New File #517

montymxb opened this issue Nov 29, 2017 · 2 comments

Comments

@montymxb
Copy link
Contributor

Cross posted from parse-server issue #4388 on behalf of @lucamorelli.

Issue Description

I'm trying to upload a video file from a cordova app client using this code

        function saveFile(filename, base64) {
            var imgFile = new Parse.File(filename, {
                base64: base64
            })
            $log.log('saving file ' + filename)
            return imgFile.save()
        }

this code works uploading files, but fails sending a video, where I have a base 64 string starting with data:video/mp4;base64,AAAAGGZ0eXBtcDQyAA.
I checked the code and I think I found the problem
this is the regexp that extract the file content
var dataUriRegexp = /^data:([a-zA-Z]*\/[a-zA-Z+.-]*);(charset=[a-zA-Z0-9\-\/\s]*,)?base64,/;
here tries to extract the content type from the datastring

          var matches = dataUriRegexp.exec(_base.slice(0, commaIndex + 1));
          // if data URI with type and charset, there will be 4 matches.
          this._source = {
            format: 'base64',
            base64: _base.slice(commaIndex + 1),
            type: matches[1]
          };

this control fails when the content type contains a number like mp4, and the matches array is null
changing the regexp to

var dataUriRegexp = /^data:([a-zA-Z]*\/[a-zA-Z0-9+.-]*);(charset=[a-zA-Z0-9\-\/\s]*,)?base64,/;
seems to work

Steps to reproduce

try to create a un file object using the filename, and a full base64 data string containing a content type with a number like video/mp4

Expected Results

to be able to save file with this content type

Actual Outcome

error evaluting the matchs array because is null

@dplewis
Copy link
Member

dplewis commented Mar 13, 2018

@montymxb Wouldn't #483 solve this issue?

@montymxb
Copy link
Contributor Author

@dplewis looks like it should actually. And the changes I requested do seem to be in place. Thanks for pointing that out again. I'm marking to look at that when I get back tonight. Looks like the regex I suggested was put into place with some modifications for this PR, initially it looks good but I want to give it another look before I green light it.

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

No branches or pull requests

2 participants