I think this is a repeat question but I can't seem to find the right answer...
I can upload png and jpeg images just fine (mern with multer) however when it comes to displaying the PNG file I have some issues.
File location is in the public/uploads folder
Successful display of JPEG (Displays JPEG correctly with the following) but fails on PNG
<img src={`${post.image}`} alt="testing"></img>
Error when it comes to PNG (404 Not Found)
GET http://localhost:3000/uploads/postImage-1637006445002-134875838-Screen%20Shot%202021-11-15%20at%205.25.09%20PM.png 404 (Not Found)
If I try the following, I get another kind of error for both JPEG and PNG
<img src={require(post.image).default} alt="testing"></img>
Cannot find module '/uploads/postImage-1637006445002-134875838-Screen Shot 2021-11-15 at 5.25.09 PM.png'
Doing an import such as below doesn't really make sense since I'm pulling the image name from a database and then referencing it's location in the public/uploads folder
import Image from 'uploads/fileName.png';
My other option is to a fileFilter on the backend and limit uploads to just JPEG but that seems limiting.
The only difference between the two that I can tell is the file type. Backend file handling is the exact same, so my question is how do I display PNG images the same exact way that I display JPEG's? Is there some config with React that I have to change?
Any help would be much appreciated. Thank you,
Your web server may be setup to receive the PNG mime type, but not to send files of this type, which would account for the 404 error you are receiving when you try to render it. Each web server is different in how this is configured.
I didn't know that spaces in the file name when uploading wouldn't get pulled properly by React. If you're running into this, what fixed my issue was removing spaces from the filename. Thanks to Steve -Cutter- Blades for pointing it out.
Related
I've got a MERN application that stores images to MongoDB. however, when trying to read the database and display the image back in the client application I keep getting the broken image icon.
I'm using Multer to successfully upload and store the images in the "/images" folder on the API side. I'm able to SEE the files being uploaded into that folder. I'm also using Path to declare the /images folder as a static folder.
on the client side I'm able to query the posts, get back the appropriate filename in the post.photo attribute and build up the source file location using a hard-coded PF constant (public folder). I'm logging out to the console that URL and when I copy and paste that built URL directly into a browser with the server running I'm able to see the picture successfully.
however, when using the URL for the image "src" I'm getting a broken image icon as shown.
I'll try to include a VERY watered down version of the code showing only relevant parts. any help would be greatly appreciated.
[Server Side][1]
[1]: https://i.stack.imgur.com/HkDbs.jpg
[Client Side][2]
[2]: https://i.stack.imgur.com/fJnXg.jpg
[Console App][3]
[3]: https://i.stack.imgur.com/KSunR.png
After weeks of wrestling with this I was finally able to get images to show in my client app! hopefully this helps someone else who might be having the same issue.
removed Helmet from the server side index.js file (it was part of a video instruction that I was following)
added a space-separated WHITELIST environment variable in the server-side .env file (ex: WHITELIST=http:http://localhost:3000)
then added the following code to my index.js code
code sample
Finally, somewhere along in the process I started getting "net::ERR_UNSAFE_PORT" errors showing up in my console. I wound up having to explicitly note my server ports like this "--explicitly-allowed-ports=5000,6000" in my browsers shortcut property by following the instructions noted here
https://superuser.com/questions/188006/how-to-fix-err-unsafe-port-error-on-chrome-when-browsing-to-unsafe-ports
that seemed to fix the issue for me!
I'm new to Salesforce surveys and I'd like to embed a URL (for this example, https://www.google.com) in an image. I've tried following their documentation here but it's a tad confusing. The survey's editor doesn't give any built-in options - this is what I have right now:
In a wild attempt I tried:
To no avail - it just displays the plain text in production. How can I embed a URL in an image (if possible)?
After researching a bit more I found this here:
"..Upload Image and select an image from your local host. You can upload only JPEG, PNG, or GIF files. The file cannot exceed 1 MB. You can’t add a hyperlink to an image. Copying inline images from external sources to the text editor is not supported."
Looks like it's not possible :(. I'm still searching for a workaround if one exists.
I want to save images from camera roll internally in my app.
I've been using react-native-image-crop-picker to import the image's base64 data and saving it with AsyncStorage.
The problem is when it comes to render Images using base64 data, it's extremely slow.
I would like to save the images and have their URIs in order to render them faster.
Refer this link How to get absolute path of a file in React-native
This Link will help you in Implementation Code Sample
Once you get the absolute path of the file rn-fetch-blob package will help you store it your file system checkout this link File system
I hope this helps, do comment if any doubts !
Well.I use nightmare to do some test taskes.It's so good for basing on electron and phatomjs.
Now, I have a question about how can I upload a image file through nightmare?
Well.I find a plugin named night-upload. After it upload a image file successfully, the page become white and has nothing to show.
So.Is there some solutions to solve this problem?
Well. The plugin of night-upload can upload a image file through nightmare.
I had write relative path of image file before. So it has the problem as I said: the browser of electron will become white and show nothing, the main process has hang up. Now I change the image file to absolute path. It works!
I am getting "The connection to the server was reset while the page was loading" error, while uploading a .docx format file. This is happening in all the browsers.
Uploading pdf, zip file formats are working perfectly.
Does anyone know why this is happening, and how it can be resolved ?
Try making a simple html upload page and see if it is possible to upload a .docx file. If it works, then your application code needs further troubleshooting and if by making a simple html upload page the error still persists; then your application code needs no changing, please do contact Godaddy hosting support for server support with this problem.
I am still having this issue with GoDaddy hosting which no longer allows uploads of some docx files. For now, a workaround is just to "Save as..." an older word .doc format which for me seems to work.