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

Unable to upload file to Parse-server-example on Heroku and MongoLab

Open grassland-curing-cfa opened this issue 10 years ago • 9 comments

I have migrated my simple Parse app to Heroku and MongoLab. And I wanted to test the file upload function with the default MongoDB GridFileAdapter.

A FILE_KEY variable has been set up properly on Heroko's Config Variables.

The Parse constructor is like:

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  restAPIKey: process.env.REST_API_KEY || '',
  javascriptKey: process.env.JAVASCRIPT_KEY || '',
  masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'http://localhost:1337',  // Don't forget to change to https if needed
  fileKey: process.env.FILE_KEY || 'myFileKey'
});

To test file upload function, I ran the following CURL command via Command Prompt: curl -X POST -H "X-Parse-Application-Id: {APP_ID}" -H "X-Parse-Master-Key: {MASTER_KEY}" -H "Content-Type: image/jpeg" --data-binary '@myimage.jpg' https://{MY_APP}.herokuapp.com/parse/files/myimage.jpg

The response was a JSON and successful as it returned a "name" and "url" to the file that was uploaded.

However, when I went to the URL on the web browser, it showed "It cannot be displayed because it contains errors."

On MongoLab, a new document can be found on "fs.files" table:

{
    "_id": {
        "$oid": "56e7991c250dd73091e07dfe"
    },
    "filename": "79c459af8569eeb5740f05d8559696e1_myimage.jpg",
    "contentType": "binary/octet-stream",
    "length": 21,
    "chunkSize": 261120,
    "uploadDate": {
        "$date": "2016-03-15T05:09:48.105Z"
    },
    "aliases": null,
    "metadata": null,
    "md5": "775a10624c6ef9a8d20996335a7a8bc5"
}

My feeling is the file was not actually uploaded successfully despite a dummy file url and name returned.

By reading thru the wiki and issues, I am assuming the problem was due to lack of a GridFileAdapter declaration in the Parse server Constructor.

If that is the case could anyone direct me where to find an instruction how to work with the default GridFileAdapter?

grassland-curing-cfa avatar Mar 15 '16 05:03 grassland-curing-cfa

What is the url you tried to open? It should be something like it: https://{MY_APP}.herokuapp.com/parse/files/YOUR_APP_ID/79c459af8569eeb5740f05d8559696e1_myimage.jpg

davimacedo avatar Mar 17 '16 20:03 davimacedo

Yes, that was the URL that I tried to access via web browser.

After I ran the cURL command to upload test image files, "fs.files" and "fs.chunks" were populated with a new document but the "chunkSize"is always 261120 regardless of the actual size of the file I uploaded. When I tried to open the uploaded using the returned URL it showed "Unable to display the file and it contains errors".

grassland-curing-cfa avatar Mar 17 '16 23:03 grassland-curing-cfa

I am in the same position essentially. I have migrated to a hosted MongoDB (ObjectRocket) and have parse-server-example running in Heroku, and this seems to work fine for reading at the moment.

But I cannot find how to save and then fetch files.

The documentation I have seen so far doesn't talk about how GridFileAdaptor stores the files or where, and inspecting the tables in the MongoDB I am not seeing anything that even remotely looks like my referenced files.

I've not yet done further to store files via my new Parse Server yet, that's my next test.

threegoblins avatar Apr 13 '16 15:04 threegoblins

You can take a look at the FilesRouter here: https://github.com/ParsePlatform/parse-server/blob/master/src/Routers/FilesRouter.js

ralphilius avatar Apr 17 '16 14:04 ralphilius

This issue is now pretty old. If you still have this issue on the Parse Server 2.2.9, can you open a new issue and include some logs and/or code that repros the issue?

drew-gross avatar May 13 '16 17:05 drew-gross

Just want to share my experience here. I have installed Parse server and Parse Dashboard on Heroku and use MongoDB on MLab. The latest version works directly with the GridFS in the MongoDB. So no extra configuration is needed and the files can be uploaded from the new dashboard. The old files which are hosted on the Parse server need to be moved to the new location because the new Parse server cannot open the files on the origin Parse server hosted on Parse.com.

flamesoft avatar Jul 11 '16 04:07 flamesoft

@flamesoft how did you handle the process of moving the old files to the new location?

ilyashev avatar Oct 17 '16 01:10 ilyashev

@ilyashev I don't have a clever way. Just did it in the new dashboard by hand. I have seen some who might have done it by some tools. But unfortunately I don't remember the link.

flamesoft avatar Oct 17 '16 04:10 flamesoft

got it. thanks for your response, @flamesoft

On Mon, Oct 17, 2016 at 12:32 AM, flamesoft [email protected] wrote:

@ilyashev https://github.com/ilyashev I don't have a clever way. Just did it in the new dashboard by hand. I have seen some who might have done it by some tools. But unfortunately I don't remember the link.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ParsePlatform/parse-server/issues/1029#issuecomment-254110543, or mute the thread https://github.com/notifications/unsubscribe-auth/AA06cc0GFvJgeboTAeubjnmMLDTXZrUaks5q0vpHgaJpZM4HwueM .

ilyashev avatar Oct 17 '16 13:10 ilyashev