4 ms·
I wonder if you could get the same functionality of AWS, with the same implementation of B2, by having a single URL to POST files to, that simply sent a redirec
by elFarto 8y ago
I wonder if you could get the same functionality of AWS, with the same implementation of B2, by having a single URL to POST files to, that simply sent a redirect to the correct location (apparently there's the 307 HTTP status code for exactly this).
E.g:
=> POST https://upload.backblaze.com/bucket/file
<= 307 redirect to https://pod-000-1007-13.backblaze.com/b2api/v1/b2_upload_file/...
=> POST https://pod-000-1007-13.backblaze.com/b2api/v1/b2_upload_file/...
- BillinghamJ 8y agoI'm not sure you could prevent the client from providing the body before you're able to stop it and tell it to redirect instead - so there's a high risk you end up with everything being uploaded twice.
- willglynn 8y ago`Expect: 100-continue` lets the server control this. If it responds "100 Continue", you upload the body. If it responds with a redirect, you redirect without uploading the body. This is standard HTTP/1.1, and it's used by the S3 API for PUT requests.
- user5994461 8y agoStrictly speaking, it's possible but it's not reliable and it shouldn't be used. A redirect on a POST never results into another POST with the same content. - API typically don't follow redirects (without special flags). Too much risk to cause damages by doing repeated calls. - Browsers follow the redirect by a GET with no data. It's typical for a completed form to redirect to another page, do not re submit the form there. There are some settings and flags to alter the behavior into what you describe but it's not a good idea to go there. It will definitely not work out of the box with much of anything.
- willglynn 8y agoThere are different kinds of redirects. See the discussion of 303 See Other vs 307 Temporary Redirect in RFC 7231: https://tools.ietf.org/html/rfc7231#section-6.4.4 https://tools.ietf.org/html/rfc7231#section-6.4.4 https://tools.ietf.org/html/rfc7231#section-6.4.7 https://tools.ietf.org/html/rfc7231#section-6.4.7 303 means "GET this new URL" while 307 means "resend your request at this URL without changing the verb or body".
- user5994461 8y agoAnd you can see that the RFC only talks in terms of should and may. It's beyond basic HTTP functionality, the RFC is basically moot at this stage and you're dealing in implementation specific details. You will have to work individually on every client you plan to support, both browsers and libraries. It can be done but it's not necessarily a good idea.
- SahAssar 8y ago307 & 308 specifically say to follow the redirect with the same method and body.
- user5994461 8y agoI invite you to try it in your favorite browser interactively, then in ajax , then curl, then python requests, then wget, then whichever software and libraries are available to you.
- ComputerGuru 8y agoIt works. We’ve been doing it to redirect http to https for api servers that have clients written in C, PHP, .NET, JavaScript and more. Http 307 is well-defined and supported.