Image Resize (PHP)

I’d like to generate resized image files (thumbnails).

I thought it could be a good idea to do so via custom event handler and invoke something like this:

However, currently I cannot figure out how to directly access the backendless file system from code.
Any advice from where to start at best?

Direct file system access is allowed only in JS(Node.js) scripts running in Backendless Hosting. Custom business logic code running in API Engine can work with files only via API.

Regards,
Mark

Do you have some sample code in JS (shoppingCartService or similar invoking File Api)?

regards,
Jens

The API doc has some samples:
Saving a file from an array of bytes: http://backendless.com/documentation/files/js/file_save_files_from_byte_arrays.htm
File download: http://backendless.com/documentation/files/js/files_file_download.htm there is no example there, but any approach for downloading a file from a URL will work. Here’s one:
http://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries

Regards, Mark

Any chances to host a JS file to which a client (android/iOS) could upload an image file?

I Could then resize it and save it via File Api.

What would be your preferred way to accomplish this task?

regards,
Jens

Yes, you should be able to do it that way. To do this, deploy your node.js script to the web/scripts folder. It must follow the expressJS pattern of accepting a request and returning a response. Any dependent node modules should be deployed to the web/scripts/node_modules directory.

In your script, you would obtain the data sent by the client from the “request” object and then do your image conversion magic.

Regards,
Mark

Has anyone done this? I would like to have a process running which will compress/resize the uploaded image files.

I tried do resize using java code but got error: Could not initialize class javax.imageio.ImageIO, inspite of import javax.imageio.ImageIO;

ImageIO does a lot of things which are not permitted by the sandbox environment where custom code runs. For example, this is only one of the security exceptions raised by things that class does:

java.security.AccessControlException: access denied (“java.lang.RuntimePermission” “loadLibrary.awt”)

So how to make image cropping in custom code using java?

@Mark: any updates?
@Aleks P: did you manage to solve it somehow?

Unfortunately no, at now i upload created by client thumb with original one

I’m thinking about doing the same for MVP so we can ship, but it’s necessary to do the resizing on the server as soon as possible.

How about using this instead:

?

I need the same for my App resizing and crop the image uploaded by the user. Any news in how to do it inside Node.js service?
Thanks

Hello @Mario_Ghersi

Is it to continue on this topic? Rotate photo registration image - #7 by stanislaw.grin

Yes I’m still looking for the right answer and sample code.

Mario