Skip to content

possible bug creating new File #4388

Closed
Closed
@lucamorelli

Description

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions