• Purchasing a license grants permission to use the software and to get Tech Support. A license purchase doesn't grant customization support.

API to post to user account and album

marcanthonyphoto

Network license
License owner
Joined
Apr 27, 2017
Messages
13
Points
53
I read the documentation on the API and got uploading to work to a users account except that you are hardcoding the name (i.e.CHV\Image::uploadToWebsite($source, 'jesse');) . I want to change the uploadtowebsite to be like this CHV\Image::uploadToWebsite($source, $user_id, $album); This way the api would upload into a users account and album based on the get statement like this.
https://www.yoursite.com/api/1/upload/?key=32f229aed6ef628b2bd0&source=http://yourphoto.com/123.jpg&user_id=youruseraccount&album=youralbumname&format=json

Can this be done? If so, how. I need this bad.
 

marcanthonyphoto

Network license
License owner
Joined
Apr 27, 2017
Messages
13
Points
53
Are you going to add that in v4? If you're going to have an API for uploading it only makes sense to allow for uploading into a users album
 

Rodolfo

Chevereto Developer
Chevereto Staff
Joined
Oct 7, 2008
Messages
15,526
Points
237
Location
Chevereto HQ
Website
rodolfoberrios.com
V3 API is just a route that listens to certain requests, every method needs to be manually added so when I add a class method that function must be manually added to the API.

V4 API will be different because it will bind every method automatically meaning that every single action or procedure will be immediately available as an API endpoint.

Day and night, V4 will be build from scratch to have this 1:1 API.
 

marcanthonyphoto

Network license
License owner
Joined
Apr 27, 2017
Messages
13
Points
53
Thanks. I did find a way to do it for the user id but I can't find a way to post into an album of that user. Here's what I added to route.api.php. Any thoughts on what I can add to post into the album name?

Right under
$route = function($handler) {
try {

I added this

$user = $_REQUEST['user'];
if (is_null($user)) {
$user = 'nouser';
}


Then I added this

$uploaded_id = CHV\Image::uploadToWebsite($source, $user);


Now when I enter something like this it posts the photo into the users account from the get statement. But any thoughts on what I can add to this code to now post into an album name in the user account?

mysite.com/api/1/upload/?key=32f229aed28b&source=http://www.test.com/image23.jpg&user=marcanthony&format=json
 
  • Like
Reactions: mkerala2

Rodolfo

Chevereto Developer
Chevereto Staff
Joined
Oct 7, 2008
Messages
15,526
Points
237
Location
Chevereto HQ
Website
rodolfoberrios.com
Easy, start by digging.

Open app/lib/classes/class.image.php and search for uploadToWebsite

And open app/routes/route.json.php and look for $uploaded_id
 

marcanthonyphoto

Network license
License owner
Joined
Apr 27, 2017
Messages
13
Points
53
Thanks for the assistance. I tried but didn't have any luck. No matter what I change it still posts into the users main account but won't post into the users album. I know you are very busy but if you can just take a minute to modify my codes to allow for it to work it would mean so much to me. I'm stuck and this is really important. If not, I understand. If you can, it would be greatly appreciated. I am looking for posting to be like this.

mysite.com/api/1/upload/?key=32f229aed28b&source=http://www.test.com/image23.jpg&user=marcanthony&album_name=thename&format=json

Here are my files www.ipixsocial.com/files.zip
 

marcanthonyphoto

Network license
License owner
Joined
Apr 27, 2017
Messages
13
Points
53
OK. I will look into that. The problem is when a user creates an album how will they know what the ID is? Also, I am having an issue with my iPhone app that I am developing. I am posting to the api using base64 as source. The problem is it is getting rejected by the server because the string is too long. Any thoughts on this? I know you're not an iPhone developer but maybe you see something that would help send a photo from my iPhone as a local file to the api.


NSData *imageData = UIImageJPEGRepresentation(_capturedImage, 0.5);



NSString *imageB64 = [imageData base64EncodingWithLineLength:0];

imageB64 = [imageB64 encodedURLString];

NSURL * url = [NSURL URLWithString:[NSString stringWithFormat: @"https://www.site.com/gallery/api/1/upload/?key=32f229aed6ef628b2bd&source=imageB64&user=marcanthony&format=json"]];



NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

[request setURL:url];

[request setHTTPMethod:mad:"POST"];
 

mkerala2

Network license
Beta tester
Joined
Jun 30, 2014
Messages
449
Points
105
Thanks. I did find a way to do it for the user id but I can't find a way to post into an album of that user. Here's what I added to route.api.php. Any thoughts on what I can add to post into the album name?

Right under
$route = function($handler) {
try {

I added this

$user = $_REQUEST['user'];
if (is_null($user)) {
$user = 'nouser';
}


Then I added this

$uploaded_id = CHV\Image::uploadToWebsite($source, $user);


Now when I enter something like this it posts the photo into the users account from the get statement. But any thoughts on what I can add to this code to now post into an album name in the user account?

mysite.com/api/1/upload/?key=32f229aed28b&source=http://www.test.com/image23.jpg&user=marcanthony&format=json
Thanks, working perfectly. This guide is more straight forward than the APIv1 document(https://chevereto.com/docs/api-v1) for enabling user account upload. The API document says "API V1 one doesn't have a way to upload images associated with a given user" which is no longer the case. The workaround given was also complex and only for a single account.