Skip to content
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

ParseFile save fails on parser-server after migration: Unable to encode an unsaved ParseFile #136

Closed
smanikandan14 opened this issue Feb 1, 2016 · 48 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@smanikandan14
Copy link

I am using parse-android SDK 1.13.0. I am able to upload file to parse's backend.

But when i change my server endpoint to migrated end point, upload fails.

{
    "code": 130,
    "error": "Invalid file upload."
}

I added console logs in file.js on parse-server i found the request.body is empty.

Files.js processCreate req: [object Object] : {} : undefined

var processCreate = function(req, res, next) {
console.log(" Files.js processCreate req:"+req+" : "+ JSON.stringify(req.body)+" : "+req.body.length
if (!req.body || !req.body.length) {
    next(new Parse.Error(Parse.Error.FILE_SAVE_ERROR,
         'Invalid file upload.'));
    return;
  }

Exception message shown on client side.

iIllegalStateException: Unable to encode an unsaved ParseFile

Seems to be an issue on the parse-server side. The request body is found empty. I reported this issue on parse-android-sdk. Since the sdk could upload to parse hosted backend. Suspect is on the parse-server side.

@smanikandan14
Copy link
Author

Reported the same on parse-android-sdk. parse-community/Parse-SDK-Android#384

@smanikandan14
Copy link
Author

@gfosco Sorry, just checking if this is a valid bug. I couldn't upload images to parse-server after migration. Any solutions appreciated.

@gfosco gfosco added the type:bug Impaired feature or lacking behavior that is likely assumed label Feb 5, 2016
@gfosco
Copy link
Contributor

gfosco commented Feb 5, 2016

Will look at this within the next day or two, looks valid, will combine other issues to point here.

@jpmassena
Copy link

@smanikandan14, are you using OkHttp dependency on you app?

As soon as I added OkHttp, I started to have some problems with my parse-server:

  • First all requests to parse-server crashed the app. The cause was that I was receiving or sending null Headers (parse-x-client-key or something similar) and ParseOkHttpClient (from the SDK) crashed.
  • I added the clientKey to the app/server and that problem went away, but now I'm getting the same error as you do. I removed the OkHttp dependency and I'm able to upload files again.

So, the issue seems to be around the SDK, at least for me as I only have problems when using OkHttp dependency on my app.

@Spacelapp
Copy link

Got the same error after migration: [Error]: Invalid file upload. (Code: 130, Version: 1.12.0)
Any news on this @gfosco ?

@JoshR604
Copy link

I am using the .NET sdk and I get this error as well 'Invalid file upload' but I suspect the bug might be in the SDK as I can upload text files and images directly to my parse-server using cURL.

@JoshR604
Copy link

I have found a solution to my issue by explicitly setting the MIME type when uploading a ParseFile.

@flovilmart
Copy link
Contributor

@gfosco idea on that, is that because we use a raw body parser and the content maybe encoded in another format depending on the client configuration (usually multipart/form-data with boundaries)

@oyvindvol
Copy link

I am using the .NET SDK to upload PFFiles (images), and also got the invalid file upload message. After setting MIME type explicitly in the PFFile like @JoshR604 said, I get this exception instead: Exception of type 'Parse.ParseException' was thrown. with no inner exception message.

When I change back to my old Parse.com-hosted server, it works fine.

@oyvindvol
Copy link

@JoshR604 Are you setting the MIME type in the ParseFile constructor? new ParseFile("filename", data, 'image/png'); ?

@JoshR604
Copy link

@oyvindvol Yes, here is the code I am using:

var file = new ParseFile ("photo.jpg", data, "image/jpeg");
await file.SaveAsync ();
parseUser.Add ("photo", file);
await parseUser.SaveAsync ();

Also, I am using the .NET sdk on Xamarin and have tested this code on iOS and Android.

@perriera
Copy link

I just discovered today that by default the migration feature of the new Parse dashboard only migrates your data. It does not migrate the contents of the ParseFile object itself. In my case I am storing jpg and png images inside a ParseFile. When I did the first mirgration the ParseFile objects migrated but they pointed towards the www.parsefss.com url. In my case I was able to by pass the need for the migration tool because I happened to have a backup/restore feature on my client's website. Where I was able to do a full backup while still on the Parse.com database. Then when I switched to my open source Parse Server with it's own MongoDB, I did a full restore. This caused the file uploading to store a brand new copy of the ParseFile images inside the MongoDB database. I was able to check this simply by doing a View Image with the browser.

So it looks like all you have to do is something similar to this and you're ready to go!

I did a double check on my website before posting this comment. The open source Parse Server uploads, edits and deletes images just fine!

@jmk2142
Copy link

jmk2142 commented Feb 17, 2016

@perriera I had a similar question about Parse.Files on the old system. Apparently a file migration tool that will migrate your files to your new MongoDB is in the works. For now, configuring your server with a fileKey (from your Parse file key) will make your server point correctly to the old files that still reside on Parse's Amazon file store. New files created on your server using Parse.File will be stored on your own MongoDB and work just fine.

@oyvindvol
Copy link

@gfosco Do you know when you will look at this bug?

@perriera
Copy link

When you do the migration as made available by Parse.com, the current implementation of that migration does not automatically copy over the images that any of your ParseFile objects have embedded in them. While the ParseFile object is migrated, the embedded image is not. It continues to point to the original storage location.

However, when you go through the trouble of re-uploading that image to your open source Parse Server from scratch it will embed the image inside very same open source Parse Server. All you have to do is look at your MongoDB to see it. As well, simply check the image in your browser to see when it is now pointing.

So it's not really a bug anymore, just an oversight. The open source Parse Server has been refined over a period of five long years. It's very well put together. It's just a matter of learning how to use it properly.

Cheers,

Perry Anderson


Unified Objects, Inc. http://www.unifiedobjects.com/

We build beautiful web and mobile apps! http://hosting.unifiedobjects.com/


perry@unifiedobjects.com

Tel: 844 440 7400

perry.anderson@gmail.com
Check out my professional profile and connect

with me on LinkedIn. http://lnkd.in/5TpErE

On Thu, Feb 18, 2016 at 4:30 PM, oyvindvol notifications@github.com wrote:

@gfosco https://github.com/gfosco Do you know when you will look at
this bug?


Reply to this email directly or view it on GitHub
#136 (comment)
.

@oyvindvol
Copy link

@perriera That`s OK, but that was not really my problem.

The problem is that when uploading images from file upload via the .NET SDK we get the error Invalid file upload.. Someone resolved this by explicitly setting MIME type when creating the ParseFile object, but this didn`t solve it for me..

@perriera
Copy link

Keep me posted! Parse Server is open source now so it's going to be up to
the open source community to maintain it.

Cheers,

Perry

Perry Anderson


Unified Objects, Inc. http://www.unifiedobjects.com/

We build beautiful web and mobile apps! http://hosting.unifiedobjects.com/


perry@unifiedobjects.com

Tel: 844 440 7400

perry.anderson@gmail.com
Check out my professional profile and connect

with me on LinkedIn. http://lnkd.in/5TpErE

On Fri, Feb 19, 2016 at 4:26 AM, oyvindvol notifications@github.com wrote:

@perriera https://github.com/perriera That`s OK, but that was not
really my problem.

The problem is that when uploading images from file upload via the .NET
SDK we get the error Invalid file upload.. Someone resolved this by
explicitly setting MIME type when creating the ParseFile object, but this
didn`t solve it for me..


Reply to this email directly or view it on GitHub
#136 (comment)
.

@cyboolo
Copy link

cyboolo commented Feb 21, 2016

any news on file upload process? @gfosco

@nlutsenko
Copy link
Contributor

Looks like we require the Content-Type for file uploads, which might not be sent at all times.
I am going to remove the restriction right now, so we no longer require the content-type on file uploads.

@oyvindvol
Copy link

@nlutsenko So, I updated my parse server to 2.1.2, and tried again uploading file from .NET SDK. Still get the same error Invalid file upload, code 130.

And this is how I create the file: new ParseFile("file", imageData).

@nlutsenko
Copy link
Contributor

The fix literally landed ~6 hours ago and 2.1.2 is about 3 days old at this point, meaning that it will be a part of 2.1.3. 😁

@oyvindvol
Copy link

@nlutsenko Ah, I`m sorry :) Thanks!

@arrivaldwis
Copy link

did this bug already fixed? I'm still get the error "invalid file upload"

thanks

@oyvindvol
Copy link

It is not released yet, it will be part of parse-server 2.1.3.

@nlutsenko
Copy link
Contributor

@vioside, that sounds super strange. Any chance you can open a separate issue for it, also would be super helpful if you would specify there how you are configuring S3 storage.

@chriscborg
Copy link
Contributor

@nlutsenko ok, issue created: #675
Thanks!

@wavo89
Copy link

wavo89 commented Mar 14, 2016

@perriera

I am experiencing this issue with Parse-Server, though it was working fine with saving images hosted on the www.parsefss.com domain, until today. I wonder if uploading through the parse.com file browser somehow caused it to not save the images from the application anymore.

Are you able to share any resources on how to take the database and re-upload it (to mLab from Heroku in my case)? What you're saying is that by using this process it will save the files to with a domain pointing to our server and not the parse.com one?

@ghost
Copy link

ghost commented Mar 19, 2016

What is the update on this.
Has this issue been resolved.

Still getting the error
Am on the android library version 1.13.0
and Parse-server version: 2.1.4

@wavo89
Copy link

wavo89 commented Mar 19, 2016

This actually was happening because I maxed out the HDD on the mongodb host I use (mLab) . Didn't realize it bc I'm used to Parse. So that may help. You also in general want to try updating the parse-server SDK, for some other things that helped me. Good luck.

On Mar 19, 2016, at 4:29 AM, Yinusa Kehinde notifications@github.com wrote:

What is the update on this.
Has this issue been resolved.

Still getting the error
Am on the android library version 1.13.0
and Parse-server version: 2.1.4


You are receiving this because you commented.
Reply to this email directly or view it on GitHub

@ghost
Copy link

ghost commented Mar 19, 2016

I was able to resolve the issue by adding a file content Type like this.
pFile = new ParseFile(data, "image/jpeg");

I would suggest that it should be updated on the documentations if contentType is a required field or ParseFile

@abbasdawood
Copy link

abbasdawood commented Jun 14, 2016

I am on the latest release of Parse Server (2.2.12), and I am still getting this (or a similar) error. Only now, the message changes to

ParseError { cherokee-server-0 code: 130, cherokee-server-0 message: 'Could not store file.InvalidParameterType: Expected params.ContentType to be a string' }

The additional bits of InvalidParameterType: Expected params.ContentType to be a string is only seen once I modify parse-server/lib/routers/FileRouter.js line number 108, to include the error

Original line (in FileRouter.js):
next(new Parse.Error(Parse.Error.FILE_SAVE_ERROR, 'Could not store file.'));

Modified to:
next(new Parse.Error(Parse.Error.FILE_SAVE_ERROR, 'Could not store file.' + err));

My Method that creates and tries to save the parsefile:

`var uploadToParse = function(filename, vendor) {
var deferred = q.defer();

var d;

var Report = new Parse.Object.extend('Report');
var report = new Report();

fs.readFile('tmp/' + filename + '.csv', function(err, data) {
    if (!err) {
        d = data.toString('base64');
        var name = vendor + Date.now().toString();
        var file = new Parse.File(name + '.csv', { base64: d }, 'text/csv'); //Adding the MIME manually doesn't help either
        report.set('report', file);
        report.set('vendor', vendor);

        report.save().then(function(report) {
            console.log('Saved report with ID ' + report.id);
            deferred.resolve(report.id);
            fs.unlink('tmp/' + filename + '.csv');
            fs.unlink('tmp/' + filename + 'temp.json');
        }, function(error) {
            deferred.reject(error);
            console.log(error);
        });
    } else {
        deferred.reject({ message: 'CSV file not found' });
    }
});
return deferred.promise;

}`

@HananeAlSamrout
Copy link

hello, i am still getting this error in the latest version (2.2.12): Error Domain=Parse Code=130 "Could not store file." UserInfo={code=130, temporary=0, error=Could not store file., NSLocalizedDescription=Could not store file.}

@abbasdawood
Copy link

Hi, can you share your S3Adapter config and initialization line from your code?

@HananeAlSamrout
Copy link

problem solved 👍 i had a problem in the s3 adapter

@roylo
Copy link

roylo commented Jul 18, 2016

hi @HananeAlSamrout , I have the same issue here just like you. Can you share your s3 adapter setting to me?

@boparski
Copy link

@HananeAlSamrout Same here: what was the problem with the S3 adapter?

@wussup
Copy link

wussup commented Jan 23, 2017

Still have error after migration with photo upload: "Invalid file upload". Use android-parse 1.13.1 and parse-server 2.3.2. Adding Content-Type "image/png" to new ParseFile do not solve problem.

Code:

private ParseFile getParseFile(Bitmap file, String filename) {
        // Convert it to byte
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        // Compress image to lower quality scale 1 - 100
        file.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] image = stream.toByteArray();
        return new ParseFile(filename, image, "image/png");
    }

ParseFile squarePhotoFile = getParseFile(squarePhoto, "square_photo.png");
squarePhoto.recycle();
squarePhotoFile.saveInBackground(new SaveInBackgroundSquarePhotoCallback(squarePhotoFile));

EDIT:

Solved, part of my code was bad:

ParseFile squarePhotoFile = new ParseFile("empty", new byte[]{});
squarePhotoFile.saveInBackground(new SaveInBackgroundSquarePhotoCallback(squarePhotoFile));

After not sending empty byte array to server, problem was solved.

@FeleciaGenet
Copy link

Getting this error out of no where now. Was working fine yesterday.

Error Domain=Parse Code=130 "Could not store file." UserInfo={code=130, temporary=0, error=Could not store file., NSLocalizedDescription=Could not store file.}

@mauriciord
Copy link

#3438 I'm having the same problem with GCS Adapter

@kittuvenkat
Copy link

@FeleciaGenet Did you get this resolved? I am facing this issue all of a sudden. Strangely I can upload images using IOS SDK but not working from Android. It doesn't matter if I use S3 adapter or default grid store adapter. I get 'Invalid file upload' error.

Parse-server: 2.3.2
Parse-android-sdk: 1.13.1

byte[] data = "Working at Parse is great!".getBytes();
ParseFile file = new ParseFile("resume.txt", data);

    file.saveInBackground(new SaveCallback() {
        public void done(ParseException e) {
            if(e!=null){
                Log.i("Image Error", e.getMessage());
            }
        }
    });

@kittuvenkat
Copy link

Solved the issue by declaring parse file as
ParseFile file = new ParseFile(data,"resume.txt");

lesson learned: Don't rely solely on documentation :)

@FeleciaGenet
Copy link

@kittuvenkat glad it worked out for you.

For what it's worth, for me the issue was that I had truly run out of space on the new database. Once I upgraded my storage, the issue was resolved.

@natanrolnik
Copy link
Contributor

natanrolnik commented Feb 9, 2017

@kittuvenkat you can help the Parse community by improving the docs 😊
The repo is https://github.com/ParsePlatform/docs and the specific file that relates to ParseFile on Android is this one: https://github.com/ParsePlatform/docs/blob/gh-pages/_includes/android/files.md
Pos are more than welcome!

@kittuvenkat
Copy link

@natanrolnik Sure. I am fairly new to parse community but will contribute what I can. Thanks for the links.

@grantespo
Copy link

The "Could not store file." error is occuring for me too out of nowhere after it was working perfectly for months. I'm not sure what is causing this. How would I know if I needed to update my storage?

@zhydanovajulia
Copy link

I have the same problem. Yesterday was working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests