Displaying Parse Images (AWS + Mongolab + Android)
I'm still having problems displaying parse images even after following all migration guide. Here's the error android is returning:
ENOENT (No such file or directory) : /data/data/com.xxxx.xxxx/cache/com.parse/files/http:/files.parsetfss.com/invalid-file-key/tfss-xxx-xxx-xxx-xxx-xxx-profile_xxxx.jpg.tmp
com.parse.ParseException: Download from S3 failed. Forbidden
So here is what I have done so far:
- migrated to AWS and MonboLab (data migrated according to parse guide)
- currently testing on Android, running latest sdk version.
- have set the fileKey in the index.js configuration
- have set the fileKey in the AWS environment variables
Here is the configuration on index.js:
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/test',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'xxxx',
masterKey: process.env.MASTER_KEY || 'xxxxxx',
fileKey: process.env.FILE_KEY || 'xxx-xxx-xx-xxx-xxxx',
facebookAppIds: ['xxxx'],
serverURL: 'http://parseserver-xxx-env.elasticbeanstalk.com/parse/'
});
Appreciate any help. Thanks!
Please post your Android code (preferably the part of upload and download of image).
Sure. I'm having the problem when trying to download. The image upload wasn't tested yet.
Here's the code to download:
private ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser.getParseFile("profile_image") != null){
byte[] profile_image_file = new byte[0];
try {
profile_image_file = currentUser.getParseFile("profile_image").getData();
} catch (ParseException e) {
e.printStackTrace();
}
Bitmap profile_image_bitmap = BitmapFactory.decodeByteArray(profile_image_file , 0, profile_image_file.length);
profile_image.setImageBitmap(profile_image_bitmap);
}
The error occurs on currentUser.getParseFile("profile_image").getData(). Here's the error log:
(HTTPLog)-Static: isSBSettingEnabled false
KnoxVpnUidStorageknoxVpnSupported API value returned is false
remove failed: ENOENT (No such file or directory) : /data/data/com.weengo.xxx/shared_prefs/WebViewChromiumPrefs.xml.bak
remove failed: ENOENT (No such file or directory) : /data/data/com.weengo.xxx/cache/com.parse/files/http:/files.parsetfss.com/invalid-file-key/tfss-785c08f9-b600-41b8-9d4b-3b8ad3553ac8-profile_FHcUZYKyhX.jpg.tmp
com.parse.ParseException: Download from S3 failed. Forbidden
at com.parse.ParseAWSRequest.onResponseAsync(ParseAWSRequest.java:43)
at com.parse.ParseRequest$3.then(ParseRequest.java:137)
It's because your data is probably empty. You need to do something like this:
ParseFile profileImage= currentUser.getParseFile("profile_image");
profileImage.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
// data has the bytes for the resume
Bitmap profile_image_bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
profileImageView.setImageBitmap(profile_image_bitmap);
} else {
// something went wrong
}
}
});
Ok, I've changed to that, but still the same error (below). This parse file exists, for instance if I only change the server endpoint back to parse ("https://api.parse.com/1/") everything works fine, this image is uploaded.
ENOENT (No such file or directory) : /data/data/com.weengo.xxx/cache/com.parse/files/http:/files.parsetfss.com/invalid-file-key/tfss-785c08f9-b600-41b8-9d4b-3b8ad3553ac8-profile_FHcUZYKyhX.jpg.tmp
Error: Download from S3 failed. Forbidden
Yes, it makes sense. As far as I know, the ParseFile.getData() method gets data from MongoDB and there is no native integration between Parser Server and S3.
The error message suggests ACL permission error ("Forbidden"). (http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html)
How are you uploading the image ?
Try to configure the file key as environment variable instead of server parameter: PARSE_SERVER_FILE_KEY https://github.com/ParsePlatform/parse-server#standalone-usage
After the migration I haven't uploaded any image. The images that exist were uploaded before the migration.
Ok, here is the app.json configured with env variables, but still, the same error. I've also rechecked the keys, they're all right.
"env": {
"PARSE_MOUNT": {
"description": "Configure Parse API route.",
"value": "/parse"
},
"PARSE_SERVER_APPLICATION_ID": {
"description": "A unique identifier for your app.",
"value": "xxxxxxx"
},
"PARSE_SERVER_MASTER_KEY": {
"description": "A key that overrides all permissions. Keep this secret.",
"value": "xxxxxx"
},
"PARSE_SERVER_CLOUD_CODE_MAIN": {
"description": "",
"value": "/cloud/main.js"
},
"PARSE_SERVER_FILE_KEY": {
"description": "",
"value": "xxx-xxx-xxx-xx-xxxxxx"
}
},
"image": "heroku/nodejs",
"addons": ["mongolab"]
Here's the index.js
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/test',
cloud: process.env.PARSE_SERVER_CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.PARSE_SERVER_APPLICATION_ID || 'xxxxx',
masterKey: process.env.PARSE_SERVER_MASTER_KEY || 'xxxxx',
fileKey: process.env.PARSE_SERVER_FILE_KEY || 'xxxx',
facebookAppIds: ['xxx'],
serverURL: 'http://parseserver-xxxx-env.elasticbeanstalk.com/parse/'
});
Thank you @leo-one The problem is that aws wasn't properly deploying all changes to the running app. So now the images are showing just fine.
But I still can't find a solution to why the current android authenticated user can't read/write records that have ACL read/write set to him. If anyone might know something, I've reported the issue here #414
Hey, ensure your Parse.com file key corresponds with that on your self-hosted server.
Guys, i am running in the same problem. In my case, i deployed my app at Heroku by connecting to the Github repo (parse-server-example) from the Heroku website. So how can i access my Node code to do your suggestions ?