Backendless Support
 
Waiting for user's response

ServerCode - File service handlers not called

Hello,

I've created a simple class with two handlers

  1. import com.backendless.Backendless;

    import com.backendless.logging.Logger;

    import com.backendless.servercode.RunnerContext;

    import com.backendless.servercode.annotation.Asset;

    @Asset( "*" )

    public class GenericFolderEventHandler extends com.backendless.servercode.extension.FilesExtender

    {

    Logger logger = Backendless.Logging.getLogger( "com.mbaas.Logger" );

    @Override

    public void beforeSaveFileFromByteArray(RunnerContext context, String fileUrlLocation, Boolean overwrite) throws Exception {

    logger.info( "before save file" );

    }

    @Override

    public void beforeDeleteFileOrDirectory(RunnerContext context, String fileUrlLocation) throws Exception {

    logger.info( "before delete file" );

    }

    }

and looks like non of this handlers is being executed while saving or deleting files.

I can see files I'm sending to appear in Backendless under "Files" tab. The same goes with deletions.

Debugger also is not reaching breakpoints (despite reaching in other handlers).

Could you please check it? My app id is CCD7530E-CD7B-3B6E-FF2E-B153FE232B00

Thanks in advance.

Best,

Matt

PS Looks like documentation (for all languages) about File Service Handler https://backendless.com/documentation/business-logic/java/bl_file_service_handler.htm doesn't introduce all possible methods.

Leave a Comment

Comments (13)

photo
1

Hi Matt,

Do you test them in the debug mode (local CodeRunner) or deployed in the Cloud?

Regards,

Mark

photo
1

Hi Mark,

both options - debugged in CodeRunner and deployed.

Thanks,

Matt

photo
1

Is it a generated code or you've written in by yourself from scratch?

photo
1

Generated.

photo
1

Hey, any updates on this?

photo
1

Hey, could you please confirm or deny this issue?

photo
1

Hello, please check your application again

photo
1

Hey Sergey, still same issue.

photo
1

Can you also provide the code with which you're saving and deleting the files?

photo
1

Hey Sergey, in case of saving I'm doing just a POST multipart request to https://api.backendless.com/v1/files/users/<userId>/<filename>

For deleting it's the same url but DELETE request obviously.

photo
1

I created the same handlers in my app and couldn't reproduce the behaviour - in my case, the handler has been executed successfully.

Can I try the same directly with your app? I mean at least creating a "beforeDelete" handler, testing it in debug mode and then testing after deployment? I am asking to be sure that it won't affect any of your applications which might be in production already.

photo
1

Yes, sure, feel free to test them, especially the beforeSave one.

photo
1

Please try the following. Use the following code in handler file:

  1. @Asset("*")
  2. public class GenericFolderEventHandler extends com.backendless.servercode.extension.FilesExtender {
  3. @Override
  4. public void beforeDeleteFileOrDirectory(RunnerContext context, String fileUrlLocation) throws Exception {
  5. System.out.println("Before delete");
  6. }
  7. @Override
  8. public void beforeSaveFileFromByteArray(RunnerContext context, String fileUrlLocation, Boolean overwrite) throws Exception {
  9. System.out.println("Before save");
  10. }
  11. }

Run CodeRunner.sh (debug mode).

Then run 2 curl commands in Terminal:

  1. curl -X DELETE -H application-id:CCD7530E-CD7B-3B6E-FF2E-B153FE232B00 -H secret-key:C1AC9844-B4A6-B5B4-FFEB-EA39F9C14E00 https://api.backendless.com/v1/files/users/DE11307D-XXXX-19C8-FFCE-503AE1F80D00/testfile.txt
  2. curl -X PUT -H Content-Type:text/plain -H application-id:CCD7530E-CD7B-3B6E-FF2E-B153FE232B00 -H secret-key:C1AC9844-B4A6-B5B4-FFEB-EA39F9C14E00 https://api.backendless.com/v1/files/binary/users/DE11307D-XXXX-19C8-FFCE-503AE1F80D00/testfile.txt -d bXkgY29vbCBub3Rl

In my case, I was able to see the corresponding two messages in Terminal where I ran CodeRunner.sh

photo