O10120240501 · 2022-11-21 16:27
```
(defun upload-region-0x0 (start end)
"Upload region between `START' and `END' to 0x0."
(interactive "r")
(kill-new
(shell-command-to-string
(format "curl -sF file=@- https://0x0.st <<-EOF
%s
EOF
"
(buffer-substring start end)))))
```
for some reason it fails when I try to execute it on any elisp code
```
<!doctype html>
<html lang=en>
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
```
But it's not server problem because when I put instead of %s any other string it works.
Does anyone have an idea how to do it correctly?
O10120240501 · 2022-11-21 16:32
Also any idea why kill-new doesn't put the string into system clipboard?
ieure · 2022-11-21 17:47
> Does anyone have an idea how to do it correctly?
Instead of shelling out to curl, use [`url.el`](https://www.emacswiki.org/emacs/UrlPackage) or [request.el](https://github.com/tkf/emacs-request).
Emacs is not bash and has built-in ways of doing many things. If you find yourself writing code that shells out to do something, there's almost always a better way.
O10120240501 · 2022-11-21 17:56
```
(defun upload-0x0 (start end)
"Upload region between \`START' and \`END' to 0x0."
(interactive "r")
(message "%s" (kill-new (substring (with-output-to-string
(call-process-region start end "curl" nil standard-output
nil "-sF" "file=@-" "https://0x0.st")) 0 -1))))
```
I have come up with this solution but I have still problem with the system clipboard because kill-new somehow only puts it in kill ring but not in the system clipboard.
luiggi_oasis · 2022-11-21 20:03
As a side note, I use ix and it works great. Highlight region, call ix, and it will upload the content and copy the url in your clipboard. Check it on melpa if your looking for alternatives.
oantolin · 2022-11-21 21:31
There is a [0x0 package](https://gitlab.com/willvaughn/emacs-0x0) you could use instead.
O10120240501 · 2022-11-22 09:16
I like to write this tinny functionalities by myself. It’s fun learning experience.
oantolin · 2022-11-22 11:04
Fair enough, I do that too.