Ticket #506 (closed Enhancement: fixed)

Opened 7 years ago

Last modified 6 years ago

files-plugin: service method for other plugins allowing creation of files in filerepo

Reported by: Malte Owned by: jri
Priority: Trivial Milestone:
Component: DeepaMehta Standard Distribution Version: 4.1.2
Keywords: Cc: jri, carolina
Complexity: 3 Area: Application Framework / API
Module: deepamehta-filemanager

Description

If I have an InputStream? at hand, I dont want to POST it via GET into our Filerepo, instead the FilesService? should provide a convenient method to store a file in the filerepo.

Per default just with a filename at the root directory of the currently configured filerepo-directory and optionally under a specific path.

Change History

comment:1 Changed 7 years ago by Malte

Furthermore it would be great if a "File"-topic would be created on the fly and returned by such a utility method.

What do you think?

comment:2 Changed 7 years ago by Malte

A "File"-topics MimeType? would then be set automatically (or optional as part of the call) by having a look at the extension of the filename in use.

comment:3 Changed 7 years ago by Malte

  • Status changed from new to closed
  • Resolution set to invalid

For now it would be also sufficient if I can request the Filerepo-Path inside of a server-side "Plugin".

Ah, as I just found this in DeepaMehta 4 Images. So this issue is actually none, it's already solved.

see

https://github.com/dgf/dm4-images/blob/master/src/main/java/de/deepamehta/plugins/images/ImagePlugin.java

comment:4 Changed 7 years ago by Malte

  • Status changed from closed to reopened
  • Resolution invalid deleted

Not quite solved, the issue remains as desribed:

If I have an InputStream?? at hand, I dont want to POST it via GET into our Filerepo, instead the FilesService?? should provide a convenient method to store a file in the filerepo.

Jri also sees the necessity to meet this needs and he said he could do it.

Thanks.

comment:5 Changed 7 years ago by dgf

  • Milestone set to Release 4.1.4

comment:6 Changed 7 years ago by jri

  • Milestone Release 4.1.4 deleted

comment:7 Changed 6 years ago by jri

  • Status changed from reopened to accepted
  • Owner set to jri

comment:8 Changed 6 years ago by jri

  • Cc carolina added

This feature would be useful for Carolina's import/export plugin as well. The exported file could be stored in the file repo and presented to the user as a File topic.

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

Files module: some refactoring (#506).

In preparation for "service method for other plugins allowing creation of files in filerepo".

See #506.

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

Files Service: add createFile() method (#506).

The server-side FilesService provides a new method:

Topic createFile(InputStream in, String path);

@param   in     The input stream the file content is read from.
@param   path   The path and filename of the file to be created.
                A repository path. Relative to the repository base path.
                Must begin with slash, no slash at the end.
                If that file exists already it is overwritten.

@return  the File topic that corresponds to the created file.

If you have an input stream at hand you can pass it directly.

If you want write a String to the file:

String str = ...
InputStream in = new ByteArrayInputStream(str.getBytes("UTF-8"))
Topic file = filesService.createFile(in, "/newfile.txt")

This example would create the file in the root directory of the DeepaMehta file repository.
Remember: by default the DeepaMehta file repository is your entire disk.
Consider setting the <dm4.filerepo.path> config property (in global pom.xml) to a directory that is writable, e.g.:

<dm4.filerepo.path>/home/alice/deepamehta-files</dm4.filerepo.path>

The specified directory must exist.

=> The createFile() method is not yet tested. Please test it!

See #506.

comment:11 Changed 6 years ago by jri

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