Upload file from my app

Hello,

I am looking for a way to upload file from a computer to the app I am developing on Nextcloud server. So far, I found lots of discussions/libraries about different ways of uploading file to nextcloud but I am not able to choose which one is the most relevant for my case.

I am developing an application for Nextcloud to display different category of activities for users. In order to enhance the design, I would like the administrators to be able to personalize each activity with an image that they could upload through the administration interface.

Is there a permanent storage area for applications in Nextcloud server ? AppData seems to be for temporary files only. Where are stored the background or the logo images that administrators can personalize in Nextcloud admin pages ? I think my images should be stored at the same place to be accessing when the user is loading my app and the associated personalization images.

Which library should I use to develop such function from the client side ? There is nextcloud-upload, nextcloud-link, nextcloud-files… and I am not able to understand correctly the difference between each of them and how to use them. I was not able to find examples or tutorials that could help me understand and develop such function in my app. Do you have any clues or pages to do that?

Thanks for the feedback,

Best regards.

Hello!

You are right, there is the AppData storage. I do not know why you think it is temporary only. The rough idea behind it: Everything user-oriented goes to the normal RootStorage while instance-oriented stuff into AppData. Small chunks of data might be better suited in the database.

I highly suspect that the admin settings or the theming will store binary blobs (like images) there as well.

The named packages are not from NC. They offer (as far as I have seen) the option to remotely access storage provided by an external NC server into other apps. That could be a web frontend that stores something permanently (think drawio where you can store to Google drive, MS OneDrive, or similar) or some nodejs app.

You, on the other hand, are running an app inside the NC server. I would suggest another approach:

  • Define an API for the uploading and retrieval of images
  • Use the adopted axios to handle the networking from the frontend
  • Install a controller that will (eventually using services or whatever matches your architecture) store/load to/from AppData

Chris

Hello. Thanks for the answer @christianlupus .

According to the documentation on AppData, it is mentionned that

Often you just want a very simple storage to have some temp files.

Thus I assumed that if I restart my server ou my Docker, the files stored in this space will be deleted. But if you tell me the opposite, I just found where to store my images :grinning_face:

Thanks for the precision. I though that Nextcloud had a library for the development of apps to ease the upload of files but it seems that I mistaken.

So I will try your solution.

I would not know of any restriction related to temp files. In fact, the AppData is stored in data folder of your installation (where also your users’ data is stored) in a folder starting with appdata_ AFAIK. So, if your data is mounted in docker, it should survive a container restart as your users’ files.

I did not say there is nothing of this kind. Look at packages starting @ nextcloud/ (without the space) on npmjs. These are (typically small) libraries to help with app development. There could be something but this will only allow access to the user’s files not to AppData (well if it’s your app, your app should manage the data :wink:).

Great that we found a solution.
Chris

Hello @christianlupus

I found 2 libraries : @nextcloud/files and @nextcloud/upload but I am not sure if they are relevant for my case. If you have some advices on those 2 libraries, I take it. But, as you mentionned, I am not sure that my app is able to write on AppData with those 2 libraries. I will investigate.

Anyway, thanks for the help. I appreciate.

As far as I understand: These are for accessing a user’s data. Not the app data. But I am glad if you could prove me wrong.