Cannot read property 'move' of null

Iam trying to upload a file in adonis but Iam I get this error can not read property of null
this is my code
async upload ({ params, request, response }) {
const profilePi= request.file(‘profile_pic’);

await profilePi.move(Headers.tmpPath('upload'),{
  name:'custom-name.jpg',
  overwrite:true
})

if(!profilePi.moved()){
  return profilePi.error()
}

return "file moved"

}

That means on this line:

you did not get the file in question. You may need to check your client request (for correct headers and file name, for example)

It return an empty object like int the photo below , Iam using postman to test my API

What headers are you sending from client side?

Content-Type should be multipart/form-data

In my hearders Iam using Content-Types as multipart/form-data but still not working

Hmm :thinking:

There is some issue about Ignitor inside your console, is it related to file upload?

Also can you share your configuration about file uploads?

Route.post(’/upload’, async({request})=>{

const profile_pic = request.file('profile_pic')
console.log(request.all())

profile_pic.move(Helpers.tmpPath(‘upload’),{
name:“csv_file”,
})

if(!profile_pic.moved()){
return profile_pic.error();
}

return “file moved sucesssed”

} )

this is my code every time that I test API in Post man I can empty object from console

Iam sending headers Content-Types multipart/form-data
iam still have the this problem

Cannot read property ‘move’ of null

You repeated the code of your question (which also your screenshots show) which does not contain the relevant information that may help to fix this.

As I said, the issue is on the client code (the request you made to upload the picture) because clearly that file is not reaching the server.

for testing my API Iam using Post Man , as my client side

I mean, can you share config/bodyParser.js files{} part?

Here is example form fullstack app

yes, I can

‘use strict’

module.exports = {
/*
|--------------------------------------------------------------------------

JSON Parser
Below settings are applied when the request body contains a JSON payload.
If you want body parser to ignore JSON payloads, then simply set types
to an empty array.

/
json: {
/

|--------------------------------------------------------------------------
| limit
|--------------------------------------------------------------------------
|
| Defines the limit of JSON that can be sent by the client. If payload
| is over 1mb it will not be processed.
|
*/
limit: ‘60mb’,

/*
|--------------------------------------------------------------------------
| strict
|--------------------------------------------------------------------------
|
| When `strict` is set to true, body parser will only parse Arrays and
| Object. Otherwise everything parseable by `JSON.parse` is parsed.
|
*/
strict: true,

/*
|--------------------------------------------------------------------------
| types
|--------------------------------------------------------------------------
|
| Which content types are processed as JSON payloads. You are free to
| add your own types here, but the request body should be parseable
| by `JSON.parse` method.
|
*/
types: [
  'application/json',
  'application/json-patch+json',
  'application/vnd.api+json',
  'application/csp-report'

]

},

/*
|--------------------------------------------------------------------------

Raw Parser

/
raw: {
types: [
'text/

]
},

/*
|--------------------------------------------------------------------------

Form Parser

*/
form: {
types: [
‘application/x-www-form-urlencoded’
]
},

/*
|--------------------------------------------------------------------------

Files Parser

*/
files: {
types: [
‘multipart/form-data’
],

/*
|--------------------------------------------------------------------------
| Max Size
|--------------------------------------------------------------------------
|
| Below value is the max size of all the files uploaded to the server. It
| is validated even before files have been processed and hard exception
| is thrown.
|
| Consider setting a reasonable value here, otherwise people may upload GB's
| of files which will keep your server busy.
|
| Also this value is considered when `autoProcess` is set to true.
|
*/
maxSize: '20mb',

/*
|--------------------------------------------------------------------------
| Auto Process
|--------------------------------------------------------------------------
|
| Whether or not to auto-process files. Since HTTP servers handle files via
| couple of specific endpoints. It is better to set this value off and
| manually process the files when required.
|
| This value can contain a boolean or an array of route patterns
| to be autoprocessed.
*/
autoProcess: false,

/*
|--------------------------------------------------------------------------
| Process Manually
|--------------------------------------------------------------------------
|
| The list of routes that should not process files and instead rely on
| manual process. This list should only contain routes when autoProcess
| is to true. Otherwise everything is processed manually.
|
*/
processManually: ['/projecto/anexos/create/:id']

/*
|--------------------------------------------------------------------------
| Temporary file name
|--------------------------------------------------------------------------
|
| Define a function, which should return a string to be used as the
| tmp file name.
|
| If not defined, Bodyparser will use `uuid` as the tmp file name.
|
| To be defined as. If you are defining the function, then do make sure
| to return a value from it.
|
| tmpFileName () {
|   return 'some-unique-value'
| }
|
*/

}
}

thanks the problem had to do with bodyParser.js
solved

hello,

thanks for your suggestion this will soved my issue

thanks and regards

2 Likes

you well come

This post was flagged by the community and is temporarily hidden.

I am also facing same issue can u clear what is exactly the issue in bodyparser