As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
Hello, I am creating simple Android app displaying few pictures and a short description. I would like to store images in Kinvey (I uploaded them to Files) and right now I would like to connect them to my collection. How can I do that?
Best Answer
P
Pranav J
said
about 5 years ago
Hi,
You are able to upload images to Files on the console. Now you want to access your uploaded files through Business Logic i.e. collection hooks, check this link. Files aren't stored directly with Kinvey (they're on Google Cloud
Storage). That's why accessing them is a little different compared to
the data in collections.
Please take a look at following code snippet. I have tested this in my environment and it worked fine:
var context = modules.backendContext;var utils = modules.utils;var appKey = context.getAppKey();var masterSecret = context.getMasterSecret();var uri ='https://'+ request.headers.host +'/blob/'+ appKey +'/'+ '<"_id" of your file>';// id variablevar authString ="Basic "+ utils.base64.encode(appKey +":"+ masterSecret);var requestOptions ={
uri:uri,
headers:{"Authorization":authString
}};var auth = modules.request.get(requestOptions,function(error, res, body){if(error){
response.error(error);}else{
response.body = JSON.parse(body);
response.complete(res.status);}});
Thanks,
Pranav
1 Comment
P
Pranav J
said
about 5 years ago
Answer
Hi,
You are able to upload images to Files on the console. Now you want to access your uploaded files through Business Logic i.e. collection hooks, check this link. Files aren't stored directly with Kinvey (they're on Google Cloud
Storage). That's why accessing them is a little different compared to
the data in collections.
Please take a look at following code snippet. I have tested this in my environment and it worked fine:
var context = modules.backendContext;var utils = modules.utils;var appKey = context.getAppKey();var masterSecret = context.getMasterSecret();var uri ='https://'+ request.headers.host +'/blob/'+ appKey +'/'+ '<"_id" of your file>';// id variablevar authString ="Basic "+ utils.base64.encode(appKey +":"+ masterSecret);var requestOptions ={
uri:uri,
headers:{"Authorization":authString
}};var auth = modules.request.get(requestOptions,function(error, res, body){if(error){
response.error(error);}else{
response.body = JSON.parse(body);
response.complete(res.status);}});
Szymon K
Hello,
I am creating simple Android app displaying few pictures and a short description. I would like to store images in Kinvey (I uploaded them to Files) and right now I would like to connect them to my collection. How can I do that?
Hi,
You are able to upload images to Files on the console. Now you want to access your uploaded files through Business Logic i.e. collection hooks, check this link. Files aren't stored directly with Kinvey (they're on Google Cloud Storage). That's why accessing them is a little different compared to the data in collections.
Please take a look at following code snippet. I have tested this in my environment and it worked fine:
Thanks,
Pranav
Pranav J
Hi,
You are able to upload images to Files on the console. Now you want to access your uploaded files through Business Logic i.e. collection hooks, check this link. Files aren't stored directly with Kinvey (they're on Google Cloud Storage). That's why accessing them is a little different compared to the data in collections.
Please take a look at following code snippet. I have tested this in my environment and it worked fine:
Thanks,
Pranav
-
How do I access query string values for GET and DELETE requests?
-
Basic Authentication in Business Logic
-
How do I cascade delete entities from related collections?
-
All BL failing with Violation Error
-
How do I send push notifications?
-
Whenever I try to query by _id, I get zero results
-
receiving SOCKETTIMEDOUT when requesting external http response
-
Unique Constraints on a collection column?
-
Need some help with grouping
-
Accessing Endpoint from Collection Hook
See all 342 topics