컬 --upload-file을 사용하여 파일 이름을 지정하십시오.

컬 --upload-file을 사용하여 파일 이름을 지정하십시오.

curl' 옵션을 사용하여 파일을 업로드할 때 --upload-file디스크에 있는 파일 이름과 다른 파일 이름을 어떻게 지정할 수 있습니까? 해당 -F옵션을 사용하면 다음을 수행할 수 있다고 생각 하지만 (또한 )을 curl -F 'file=@/path/to/file/badname;filename=goodname'사용하여 동등한 작업을 수행하는 방법을 잘 모르겠습니다 . 업로드된 파일에 특정 파일 이름이 있어야 하는 API를 사용하고 있지만 올바르게 업로드할 수 있도록 파일을 디스크에 복사하고 싶지 않습니다.--upload-file-T

답변1

이 시도:

곱슬URL>/좋은 이름- 파일 업로드하다잘못된 파일 이름

예:

curl http://example.com/goodname.html --upload-file badfilename.html

나는 이것을 시도하고 goodname.html다음과 같은 파일을 성공적으로 업로드했습니다. :)

답변2

컬 -v --user '사용자 이름:비밀번호' --upload-file {경로}/{binaire} {your_url}/{binaire}

답변3

--form (-F) 옵션과 함께 POST 메서드를 사용하여 파일을 업로드하면 컬은 multipart/form-data 콘텐츠 유형을 사용합니다.

POST /test.html HTTP/1.1
Host: example.org
Content-Type: multipart/form-data;boundary="boundary"

--boundary
Content-Disposition: form-data; name="field1"

value1
--boundary
Content-Disposition: form-data; name="field2"; filename="example.txt"

value2
--boundary--

보시다시피 파일 이름을 입력할 수 있는 공간이 있습니다. 그러나 --upload-file (-T)을 사용하면 컬은 PUT 메서드를 사용하며 요청 본문에는 고유한 파일 본문만 포함되므로 그러한 장소는 없습니다.

PUT /test.html HTTP/1.1
Host: example.org

file content

여기서 유일한 파일 이름은 URL 자체입니다: test.html

답변4

--url다음과 같이 컬의 옵션을 사용하십시오.

curl --upload-file /path/to/file/badname --url http://serverip/remotedir/goodname

관련 정보