ServerCode - File service handlers not called

Hello,

I’ve created a simple class with two handlers

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.

Hi Matt,

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

Regards,
Mark

Hi Mark,

both options - debugged in CodeRunner and deployed.

Thanks,
Matt

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

Generated.

Hey, any updates on this?

Hey, could you please confirm or deny this issue?

Hello, please check your application again

Hey Sergey, still same issue.

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

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.

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.

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

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

@Asset("*")
public class GenericFolderEventHandler extends com.backendless.servercode.extension.FilesExtender {


    @Override
    public void beforeDeleteFileOrDirectory(RunnerContext context, String fileUrlLocation) throws Exception {
        System.out.println("Before delete");
    }


    @Override
    public void beforeSaveFileFromByteArray(RunnerContext context, String fileUrlLocation, Boolean overwrite) throws Exception {
        System.out.println("Before save");
    }


}

Run CodeRunner.sh (debug mode).

Then run 2 curl commands in Terminal:

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
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