pingvin-share icon indicating copy to clipboard operation
pingvin-share copied to clipboard

🚀 Feature: Upload files with CURL

Open avesst opened this issue 1 year ago • 8 comments

🔖 Feature description

Would be cool to have the ability to be able to upload files with CURL and just have the generated URL be returned.

Allow unauthenticated if unauthenticated shares are enabled, or authenticated through a token connected to your account.

🎤 Pitch

Be able to easily upload files through the terminal, integrate into scripts etc.. The sky's the limit!

avesst avatar Nov 06 '23 16:11 avesst

It's actually already possible, though not documented. There are a couple of gotchas, and it might break when the new features come in, but at this time I have a working script to upload files.

  • You need to prepend files with at least a comma ,, the exact format the frontend uses is data:application/octet-stream:base64,
  • You need to base64 files before sending
  • You need to specify the Content-Type header with the value set to application/octet-stream specifically
  • You need to use --data-binary @${fileName} to set the body.
  • For files larger than 10Mb, you have to chunk the files into exactly 10Mb chunks. Example for the command: curl -v -X POST -sH "content-type: application/octet-stream" -b ${auth} --data-binary "@${fileName}" ${pingvinUrl}/shares/${shareId}/files$args

If you need a clearer example of this, you can upload a file using the frontend and inspect the network calls. Hope this helps!

tdompierre avatar Feb 05 '24 03:02 tdompierre

I am also looking to upload files through the terminal via CURL. Been looking for a simple, easy to setup, lightweight app that can accept files from CURL without any authentication. Seems to be a bigger ask than I would have figured though Pingvin seems to be the closest thus far!

@tdompierre Since you've gotten CURL to work with Pingvin, I'm hoping you can provide some insight. I am not a developer so forgive me for my ignorance. I have no idea how to even begin with inspecting the network calls between the frontend and backend. I have Pingvin running in a Docker container on UnRAID. I just setup Netdata in another docker container and hope that I can use that for inspecting the network traffic.

Are there any tools or procedures you can recommend for inspecting the traffic between the frontend and backend? Things to look out for?

MrZell avatar May 06 '24 23:05 MrZell

I've been exploring a potential feature that would enable file sharing from a remote server via CLI. If this aligns with the project's goals, I'd be eager to contribute a PR for this functionality.

Here's an overview of the proposed workflow:

  1. File Upload: Users could upload a single, non-chunked file via a PUT request: PUT https://example.com/api/shares/:shareId/files/:filename

    • If the shareId doesn't exist, it would be created
    • Requests without proper permissions would be denied
    • Existing files would be overwritten
  2. Secure Link Generation: To enhance security, we could implement a feature in the Web GUI's Share page (/share/xxxx) that includes a "Copy Upload Link" button. This would generate a one-time file upload link: https://example.com/api/shares/:shareId/files/:filename?token=xxxxx

  3. Short Links: For improved usability, especially in clipboard-restricted environments, we could create shorter upload links. This would involve:

    • Implementing a simple URL shortening service
    • Using Next.js for forwarding
    • Resulting in concise links like: https://example.com/s/:uploadKey/:filename

Although this may not be a common requirement, it could potentially add significant value for certain use cases. Further discussion on these ideas and consideration of whether this functionality would be a good fit for the project could be beneficial.

There might be potential benefits and challenges with this approach. Any feedback or thoughts on how to refine or implement this feature would be appreciated.

IvanLi-CN avatar Jul 25 '24 17:07 IvanLi-CN

@stonith404, in case you missed this, I'd like to hear your thoughts on this feature. What's your take on it?

IvanLi-CN avatar Jul 28 '24 04:07 IvanLi-CN

@IvanLi-CN Sorry for my late reply. Yes, I like these suggestions and would love if you want to contribute to this feature.

Point 3 could get a bit complicated as currently it is possible to upload multiple files with the same name. But I think we could remove the ability to upload multiple files with the same name as this is probably not commonly used.

stonith404 avatar Jul 29 '24 14:07 stonith404

@stonith404 Thank you for the reminder. I will consider implementing logic in this part to prevent overwriting existing files with the same name.

IvanLi-CN avatar Jul 29 '24 16:07 IvanLi-CN

That'd be an awesome addition, I searched for a replace for bashupload.com, which seems outdated since at least 2 years, beaing able to do this kind of upload/ download would be awesome! Because many selfhosters often work in terminal-only enviroments where such things are just the best way to copy files, however trusting a public instance with potentionally personal files is always risky.

so a huge +1 from me

CrazyWolf13 avatar Aug 04 '24 15:08 CrazyWolf13

bashupload.com

I really like it! I just tried it out and found bashupload.com to be excellent for temporarily sharing individual files.

Thank you so much, this project has inspired me! I'll reference its implementation and include share and file information in the response.

IvanLi-CN avatar Aug 04 '24 15:08 IvanLi-CN