Skip to content

Commit

Permalink
add filename option for formdata
Browse files Browse the repository at this point in the history
  • Loading branch information
watzon committed Jan 13, 2025
1 parent 91b70f4 commit 5f153a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions internal/server/services/paste.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ func (s *PasteService) UploadPaste(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusInternalServerError, "Failed to read file content")
}

// Get filename from form field if available
if file.Filename != "" {
// First check for a filename in form field
if formFilename := c.FormValue("filename"); formFilename != "" {
filename = formFilename
} else if file.Filename != "" { // Fall back to uploaded file's filename
filename = file.Filename
}
} else if p.URL != "" {
Expand Down
5 changes: 3 additions & 2 deletions views/docs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@
<div class="labeled-code-block">
<span class="command-label curl-label">CURL</span>
<div class="code-block">
<code>curl -X POST -F "file=@path/to/file.txt" {{baseUrlHost}}/p</code>
<button class="action-btn" data-clipboard data-clipboard-content="curl -X POST -F 'file=@path/to/file.txt' {{baseUrlHost}}/p"><span>Copy</span></button>
<code>curl -X POST -F "file=@path/to/file.txt" -F "filename=custom_name.txt" {{baseUrlHost}}/p</code>
<button class="action-btn" data-clipboard data-clipboard-content="curl -X POST -F 'file=@path/to/file.txt' -F 'filename=custom_name.txt' {{baseUrlHost}}/p"><span>Copy</span></button>
</div>
</div>
<dl>
<dt>Form fields:</dt>
<dd>
<ul>
<li><code>file</code> - The file to upload</li>
<li><code>filename</code> - (optional) Custom filename for the paste (overrides the uploaded file's name)</li>
<li><code>private</code> - (optional) Set to "true" to make the paste private</li>
<li><code>expires_in</code> - (optional) Duration string for paste expiry (e.g. "24h", "7d")</li>
</ul>
Expand Down

0 comments on commit 5f153a0

Please sign in to comment.