Add URL encoding to transfer function to handle whitespaces#548
Open
junoh-moon wants to merge 2 commits intodutchcoders:mainfrom
Open
Add URL encoding to transfer function to handle whitespaces#548junoh-moon wants to merge 2 commits intodutchcoders:mainfrom
junoh-moon wants to merge 2 commits intodutchcoders:mainfrom
Conversation
Add URL encoding functionality to the `transfer` function in `README.md` so that file names with spaces can be uploaded correctly. Also, the code uses the `_urlencode` function written in Python. This commit includes changes to the following: - Update the `transfer` function to use `_urlencode` for encoding the file names as URL. - Add the `_urlencode` function to URL encode the file names. Note: This change improves the functionality of the `transfer` function by making it more usable.
Collaborator
|
hi @snowphone , thanks for the PR please, see my comment at #546 (comment) the best solution would be to avoid vs so no need for urlencode and $file_name |
The transfer function no more relies on _urlencode function and just uploads to https://transfer.sh
Contributor
Author
|
Wow it's too simple 😂 |
paolafrancesca
requested changes
May 19, 2023
| ##### Add this to .bashrc or .zshrc or its equivalent | ||
| ```bash | ||
| transfer(){ if [ $# -eq 0 ];then echo "No arguments specified.\nUsage:\n transfer <file|directory>\n ... | transfer <file_name>">&2;return 1;fi;if tty -s;then file="$1";file_name=$(basename "$file");if [ ! -e "$file" ];then echo "$file: No such file or directory">&2;return 1;fi;if [ -d "$file" ];then file_name="$file_name.zip" ,;(cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null,;else cat "$file"|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;} | ||
| transfer(){ if [ $# -eq 0 ];then echo "No arguments specified.\nUsage:\n transfer <file|directory>\n ... | transfer <file_name>">&2;return 1;fi;if tty -s;then file="$1";file_name=$(basename "$file");if [ ! -e "$file" ];then echo "$file: No such file or directory">&2;return 1;fi;if [ -d "$file" ];then file_name="$file_name.zip" ,;(cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "https://transfer.sh/"|tee /dev/null;else cat "$file"|curl --progress-bar --upload-file "-" "https://transfer.sh/"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "https://transfer.sh/"|tee /dev/null;fi;} |
Collaborator
There was a problem hiding this comment.
if [ -d "$file" ];then file_name="$file_name.zip" ,;(cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "https://transfer.sh/"|tee /dev/null;
here $file is a directory, we cd into it and zip recursively sending output to stdout, curl get from stdin the upload file from stdin.
we should change to zip to file and use it for curl
else cat "$file"|curl --progress-bar --upload-file "-" "https://transfer.sh/"|tee /dev/null;fi
same here: it's not enough to remove $file_name, we should remove cat and curl getting the upload file from stdin:
else curl --progress-bar --upload-file "$file" "https://transfer.sh/"|tee /dev/null;fi
transfer(){
if [ $# -eq 0 ];then
echo "No arguments specified.\nUsage:\n transfer <file|directory>\n ... | transfer <file_name>">&2;
return 1;
fi;
if tty -s; then
file_name=$(basename "$1");
if [ ! -e "$1" ];then
echo "$1: No such file or directory">&2;
return 1;
fi;
if [ -d "$1" ];then
zip_file="$1.zip";
pushd "$1";
zip -r -q "$zip_file" . && curl --progress-bar --upload-file "$zip_file" "https://transfer.sh/"|tee /dev/null && rm "$zip_file";
popd;
else
curl --progress-bar --upload-file "$file" "https://transfer.sh/"|tee /dev/null;
fi;
else
curl --progress-bar --upload-file "$1" "https://transfer.sh/"|tee /dev/null;
fi;
}
this should be the proper one: please @snowphone check if it works for you and feel free to push the change :)
thanks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add URL encoding functionality to the
transferfunction inREADME.mdso that file names with spaces can be uploaded correctly (e.g.hello world.json).Also, the code uses the
_urlencodefunction written in Python3. I know not every *nix OS includes Python3 by default but I'm familiar with Python and I don't know how to make it more portable.This commit includes changes to the following:
transferfunction to use_urlencodefor encoding the file names as URL._urlencodefunction to URL encode the file names.Since this oneliner is too hard to review, I uploaded formatted code too:
before.txt
after.txt
If this PR is okay, I'll make a PR to tranfer.sh-web too