If I upload an image via form and then want to grab it via next.js api and display via Image component I have 400 Bad Request response. Image component says "Could not load the image". Tried to specify domain in config and use Loader, the same result. More than that, I can't access new uploaded images directly via browser url bar. But if I rebuild the project those previously uploaded images finally displays and there is no 400 error. I upload images in /public/uploads directory. This problem happens only in production mode (npm run build, npm run start). There is no such problem when I work with it in dev mode locally (npm run dev). How to make freshly uploaded images correctly displays without rebuilding a project?
next.js 400 bad request after trying to access just uploaded image
894 Views Asked by holycreeper At
1
There are 1 best solutions below
Related Questions in REACTJS
- What is `_dereq_()` inside React?
- React TypeError: React.renderComponent is not a function
- React - saving a component in the ref callback
- React Rails component: manually triggering a re-render
- React, ES6 - getInitialState was defined on a plain JavaScript class
- How to get multiple selected options value in React JS?
- React.render replace container instead of inserting into
- reactjs datagrid use html
- props is not initialized in react component
- How to display xml data using Reactjs
- hooking up the data model in ReactJS - syntax
- ReactJS: How to use an immutable empty array or object
- How to use Sinon.js FakeXMLHttpRequest with superagent?
- React select onChange is not working
- ReactJS - Tutorial Comment System > Threaded commenting
Related Questions in IMAGE
- Add image to JCheckBoxMenuItem
- Display images on Django Template Site
- How to resize images with PHP PARSE SDK
- Animation in Java on top of JPanel
- Slow performance on ipad erasing image
- What are the pros and cons of the picture element?
- Carrierwave file upload with different file types
- How to use annotorious with angular
- Images not showing when uploaded to server
- ImageView doesn't show up
- Image Resizing adjusts ratio
- Displaying bitmap image on Android (OpenCV)
- Class 'Imagick' not found - PHP and Windows
- Image position - randomly select position
- Replace image 1 with image 2 after 5 sec
Related Questions in NEXT.JS
- Getting babel build errors with the next.js getting started example
- Request Graphql api running on different port from Next.js app in development mode localhost
- Session lost when refresh the page (Next, react, isomorphism)
- HOC: A valid React element (or null) must be returned
- vscode launch config for next.js app
- Next.js + Redux server side rendering: Has data, but doesn't render on server side
- When to use a react framework such as Next or Gatsby vs Create React App
- Error: spawn EACCES on Heroku with Next.js
- Docker compose npm script command not found
- Error when using custom domain with Next.js on Heroku
- ReactJs, next JS, express and redux boilerplate
- Cannot use @import in css
- Next JS nested routing
- internal server error when deploying NextJs to firebase
- MaterialUI together with styled-components, SSR
Related Questions in UPLOAD
- PHP don't use temp file for upload
- Error 500 Creating default object from empty value when uploading a file
- Upload file to ftp with unique name in asp.net c#
- Media files end up in in a pycharm subdirectory when uploading
- partly upload your input from a file
- How to create file upload like gmail?
- How to Upload file onclick of button of type=button not type=submit in mvc4 using html begin form
- Add metadata (Exif) to base64
- Laravel upload Csv error
- jQuery file upload how to get number of files queued and uploaded
- How to upload an image using image url from web in javascript or jquery?
- Perl FTP uploading empty file to server
- Upload form inside Drupal block
- $_FILES is empty when upload in PHP
- Why am I missing "filename" and "Content-Type" while uploading image using form-data?
Related Questions in 400-BAD-REQUEST
- S3 Delete Object 400 Bad Request
- Gitlab CI/CD AWS ECR authorization "Error response from daemon: login attempt to https://XXXXXXXX failed with status: 400 Bad Request"
- Sending enum via PUT method, Retrofit | Error 400
- next.js 400 bad request after trying to access just uploaded image
- MEXC-Global do a test order from the API v3
- Configured APEX Rest Data Source, Unable to POST data using it
- Next js Dynamic Routes image gives 400 error
- How to get responseBody from WebClientResponseException?
- Why am I getting 400 error "You cannot share this item because it has been flagged as inappropriate." using Google Drive api for file sharing
- Flutter Serverpod returns 400 error on sample project
- Request flow when AWS WAF, ALB associated and ALB 4xx
- NGINX throwing 400 whenever the request is having headers key with space
- Bad request instead of message
- AWS CloudFront returning bad request from Spring WebClient but working from Postman
- 400 bad request in "POST" request in django react
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Summary
Write a custom api endpoint to serve uploaded content, because Next.JS does not support this natively
I ran into this problem as well. I was uploading temporary images to
public/_i. During development withnext run deveverything appeared great, but once I built and ran in prod mode I started seeing:I looked into loaders and setting custom headers for that path. None of it worked.
Turns out, **Next.JS encourages uploading dynamic content to a separate service or cdn. ** They do not encourage dynamically serving image content like this, and it may be considered an anti-pattern. Under the image optimization page they make the case:
This is demonstrated by the fact that your content appeared after you rebuilt. That is because the build system has cached your uploaded image as if it were static content.
Despite all of this, if you (like me) want to proceed, this is what I did:
<Image />with a regular<img />And that should be all you need.