Skip to content

possible bug creating new File #4388

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
lucamorelli opened this issue Nov 26, 2017 · 9 comments
Closed

possible bug creating new File #4388

lucamorelli opened this issue Nov 26, 2017 · 9 comments

Comments

@lucamorelli
Copy link

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

@paulovitin
Copy link
Contributor

What version of parse-server?

@lucamorelli
Copy link
Author

latest version, the packages of the app are updated

@paulovitin
Copy link
Contributor

paulovitin commented Nov 28, 2017

You need to remove the "data:video/mp4;base64,".

Check the docs http://docs.parseplatform.org/js/guide/#files

@lucamorelli
Copy link
Author

I see two constructor in the File class: one accept the filename and all the data as base64 string, and this works correctly with jpg, png files and so, and another where I can remove this part but I have to send the content type as third param. I already made this change as a workaround, but I don't understand why the first constructor works with just some content type giving this unclear error message

@paulovitin
Copy link
Contributor

Maybe @flovilmart can be give to you a better response.

@montymxb
Copy link
Contributor

@lucamorelli that looks about right. I swear I've seen this somewhere else in one of the sdks as well, in terms of a regex parsing a content-type and not expecting a digit in the second half. Can you provide a link to where this is in the server so I can take a look?

@flovilmart
Copy link
Contributor

It’s in the JS SDK, please open an issue on this project instead.

Thanks!

@montymxb
Copy link
Contributor

montymxb commented Nov 29, 2017

@lucamorelli I went ahead and opened up #517 in the JS sdk regarding this so we can address it there.

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

4 participants