multipart/form-data
and loading the file in binary form in the request body. To work in the production environment, nginx is used to authorize and process slow connections. As a client library, you can use the jQuery File Uploader .$GOPATH
environment variable. $ brew install go $ mkdir $HOME/go
# Add this line in your .zshrc or .bash_profile export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin
$ brew install git mercurial svn bazaar
$ brew install imagemagick
$ go get github.com/kavkaz/pavo
$ go get -u github.com/kavkaz/pavo/...
$ pavo --storage=$GOPATH/src/github.com/kavkaz/pavo/dummy/root_storage
--storage
option. A service with a basic example will be available at localhost:9073/example/jfu-basic.html
localhost:9073/example/jfu-basic.html
. To specify a different host and port, use the console option --host
. { "files": [ { "dir": "/image/2014/6s/1c5cnx", "name": "original_user_filename.jpg", "type": "image", "versions": { "original": { "filename": "original-1qeh.jpg", "height": 420, "size": 28057, "url": "/image/2014/6s/1c5cnx/original-1qeh.jpg", "width": 300 }, "thumbnail": { "filename": "thumbnail-1qef.jpg", "height": 90, "size": 3566, "url": "/image/2014/6s/1c5cnx/thumbnail-1qef.jpg", "width": 120 } } } ], "status": "ok" }
POST /files HTTP/1.1 Content-Length: 21929 Content-Type: multipart/form-data; boundary=----5XhQf4IXV9Q26uHM ------5XhQf4IXV9Q26uHM Content-Disposition: form-data; name="files[]"; filename="pic.jpg" Content-Type: image/jpeg ...bytes...
Content-Type
header, the value of the boundary
passed, which serves to separate the values in the request body. Thus, you can transfer several files in one request. jQuery File Upload has the appropriate option for sending multiple files. POST /files HTTP/1.1 Content-Length: 21744 Content-Disposition: attachment; filename="pic.jpg" ...bytes...
Content-Disposition
header. POST /files HTTP/1.1 Content-Length: 10240 Content-Range: bytes 0-10239/36431 Content-Disposition: attachment; filename="pic.jpg" Cookie:pavo=377cb76c-2538-40d3-a3d0-13d86d206ba7 ...bytes...
Content-Range
header contains information about what part of the file the client is betraying and what is the size of the original file. If the last piece is loaded, the server completes the download procedure and generates a response with the data about the file received and its versions.--host
and --storage
. Specify host:port
to start the web server and the root directory of the repository, respectively./files
. In the query_string converts
parameter, converts
can pass the conversion parameters for images. For example: POST /files?converts={"pic":"400x300"}
120x90
. server { listen 80; server_name pavo.local; access_log /usr/local/var/log/nginx/pavo/access.log; error_log /usr/local/var/log/nginx/pavo/error.log notice; location /auth { internal; proxy_method GET; proxy_set_header Content-Length ""; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass_request_body off; proxy_pass http://localhost:3000/auth/url/in/your/app; client_max_body_size 0; } location /files { auth_request /auth; client_body_temp_path /tmp; client_body_in_file_only on; client_body_buffer_size 521K; client_max_body_size 10G; proxy_pass_request_headers on; proxy_set_header X-FILE $request_body_file; proxy_pass_request_body off; proxy_set_header Content-Length 0; proxy_pass http://127.0.0.1:9073; } location / { root /Path/To/Root/Of/Storage; } }
client_body_temp_path
option./auth
, which in turn proxies the headers of the original request to the server of the main application. In case of successful authorization, the server should return an empty body with the response status code 200
.X-File
key, and the value is the path to the temporary file with the request body. And only after that the resulting request (headers and empty body) is sent to the application pavo. It processes the request, saving the files, and returns a response with the data about the uploaded files in JSON format.Source: https://habr.com/ru/post/234693/
All Articles