Ticket #655 (closed Enhancement: fixed)

Opened 6 years ago

Last modified 6 years ago

Files API: the upload feature should be more flexible

Reported by: jri Owned by: jri
Priority: Major Milestone: Release 4.3
Component: DeepaMehta Standard Distribution Version: 4.2
Keywords: Cc: dgf, Malte, carolina
Complexity: 3 Area: Application Framework / API
Module: deepamehta-files

Description (last modified by jri) (diff)

Currently the Files plugin's (client-side) open_upload_dialog() utility method POST's the selected file to the Files service (which stores it in the DM file repo at the specified path).

The open_upload_dialog() method should be more flexible in several terms:

  • allow the caller to POST the file to an arbitrary service and leave file handling up to that service.
  • allow the respective service method to return arbitrary (JSON) data.

At server-side the UploadedFile class should provide methods to access the contents of the uploaded file. (For the moment the only option is to write the file to disk.)

This is needed for the import/export plugin carolina is working on.

Change History

comment:1 Changed 6 years ago by jri

  • Status changed from new to accepted

comment:2 Changed 6 years ago by Jörg Richter

Files module: upload to arbitrary services (#655).

BREAKING CHANGE

Client-side Files API:

dm4c.get_plugin("de.deepamehta.files").open_upload_dialog(upload_url, callback)

The first parameter of the open_upload_dialog() method is now upload_url (instead of path). As argument the full URL (with or without host) is passed. Thus the user-selected file can be uploaded to any service, not just the /files service.

Example: uploading a file to a (fictitious) import/export plugin and invoking its "import" method:

...open_upload_dialog("/import-export/import", callback)

At server-side the plugin receives the upload by providing a resource method which consumes multipart/form-data and has UploadedFile as the entity parameter.

import de.deepamehta.plugins.files.UploadedFile;

@Path("/import-export")
@Produces("application/json")
public class ImportExportPlugin extends PluginActivator {

    @POST
    @Path("/import")
    @Consumes("multipart/form-data")
    public ImportedFile importFile(UploadedFile file) {
        ...
        return new ImportedFile(...)
    }

The resource methods can return any object which is JSONEnabled. That object is received at client-side as the argument to the callback method (as specified in the open_upload_dialog() call).

Note: while ImportedFile is a fictitious class in this example, the UploadedFile class is provided by the Files plugin.

See #655

comment:3 Changed 6 years ago by jri

  • Description modified (diff)

comment:4 Changed 6 years ago by Jörg Richter

Files module: access uploaded file content (#655).

The Files APIs de.deepamehta.plugins.files.UploadedFile class provides 5 additional public methods for accessing the uploaded file's content and for writing it to disk.

String getString()
String getString(String encoding)
byte[] getBytes()
InputStream getInputStream()

void write(File file)

See #655

comment:5 Changed 6 years ago by jri

  • Status changed from accepted to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.