parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

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

Open smanikandan14 opened this issue 10 years ago • 48 comments

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 avatar Feb 01 '16 18:02 smanikandan14

Reported the same on parse-android-sdk. https://github.com/ParsePlatform/Parse-SDK-Android/issues/384

smanikandan14 avatar Feb 01 '16 18:02 smanikandan14

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

smanikandan14 avatar Feb 03 '16 03:02 smanikandan14

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

gfosco avatar Feb 05 '16 03:02 gfosco

@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.

jpmassena avatar Feb 07 '16 01:02 jpmassena

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

Spacelapp avatar Feb 07 '16 11:02 Spacelapp

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 avatar Feb 11 '16 07:02 JoshR604

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

JoshR604 avatar Feb 11 '16 18:02 JoshR604

@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)

flovilmart avatar Feb 16 '16 04:02 flovilmart

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 avatar Feb 16 '16 08:02 oyvindvol

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

oyvindvol avatar Feb 16 '16 09:02 oyvindvol

@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.

JoshR604 avatar Feb 16 '16 09:02 JoshR604

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!

perriera avatar Feb 17 '16 02:02 perriera

@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.

jmk2142 avatar Feb 17 '16 03:02 jmk2142

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

oyvindvol avatar Feb 18 '16 19:02 oyvindvol

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/


[email protected]

Tel: 844 440 7400

[email protected] 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 [email protected] 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 https://github.com/ParsePlatform/parse-server/issues/136#issuecomment-185891284 .

perriera avatar Feb 19 '16 00:02 perriera

@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..

oyvindvol avatar Feb 19 '16 07:02 oyvindvol

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/


[email protected]

Tel: 844 440 7400

[email protected] 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 [email protected] 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 https://github.com/ParsePlatform/parse-server/issues/136#issuecomment-186108202 .

perriera avatar Feb 19 '16 10:02 perriera

any news on file upload process? @gfosco

cyboolo avatar Feb 21 '16 14:02 cyboolo

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.

nlutsenko avatar Feb 22 '16 22:02 nlutsenko

@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).

oyvindvol avatar Feb 23 '16 07:02 oyvindvol