You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fetch(path, req)
.then(response => {
if (response.status === 307) {
// Handle redirection
const redirectUrl = response.headers.get('location');
if (redirectUrl) {
return fetch(redirectUrl, req); // Follow the redirection
} else {
throw new Error('Redirect URL not found in Location header.');
}
}
return response; // Proceed with the original response if not redirected
})
.then(response => {
// GIF section
const contentType = response.headers.get('content-type');
if (contentType === null) {
console.warn(
'The image you loaded does not have a Content-Type header. If you are using the online editor consider reuploading the asset.'
);
}
...
Potential Other Improvements
This solution can also be used to catch other responses (such as server errors, 404 file not founds...) and create more specific error messaging for friendly error messaging, instead of using the generic one for file loads.
The text was updated successfully, but these errors were encountered:
In terminal, curl -v https://openprocessing.org/sketch/724441/thumbnail helps identify where redirect goes
Based on curl above, the redirect goes here: https://kyoko.openprocessing.org/thumbnails/[email protected] - although this is the conclusion of the redirect, it also does NOT work in loadImage. (However, both URLs do work in HTML: <img src="https://kyoko.openprocessing.org/thumbnails/[email protected]%22"/> <img src="https://openprocessing.org/sketch/724441/thumbnail"/> so that confirms that redirect and/or CORS is part of the issue)
In terminal, curl -I https://kyoko.openprocessing.org/thumbnails/[email protected] shows that “content-type: binary/octet-stream” - which is not an image. This is also noticeable when you click on the link: a file attachment is downloaded.
As an example, curl -I https://raw.githubusercontent.com/processing/p5.js/main/contributor_docs/images/p5-readme-sketch.png on something that works as an image gets “content-type: image/png”
Tagging image area stewards @cgusb, @albertomancia, @ramya202000, @hannahvy, @robin-haxx - is there a way to handle this already - especially since as far as I can tell, binary data can be rendered as an image? As for a fix, loadImage uses fetch and should be carrying out the redirect the same as the browser, so what could be the cause of one or both of the above? Could it be the additional explicit use of Request?
Hello @ksen0,
Thank you, your review was really helpful. I investigated further per your review, and found out that it was actually a CORS rejection the server side that was redirected to (kyoko.). I fixed the CORS headers and now it is working.
I also confirmed that fetch follows redirects per below: https://stackoverflow.com/questions/39735496/redirect-after-a-fetch-post-call
Most appropriate sub-area of p5.js?
p5.js version
1.11.1
Web browser and version
Safari 18.1
Operating system
MacOSX
Steps to reproduce this
Steps:
Snippet:
Here is an example: https://openprocessing.org/sketch/2012972
Suggested solution:
Add redirection to the loadImage function if the response status is 307. ChatGPT generated solution below:
p5.js/src/image/loading_displaying.js
Line 108 in 33883e5
Potential Other Improvements
This solution can also be used to catch other responses (such as server errors, 404 file not founds...) and create more specific error messaging for friendly error messaging, instead of using the generic one for file loads.
The text was updated successfully, but these errors were encountered: