قالب وردپرس درنا توس
Home / IOS Development / javascript – Missing request query request

javascript – Missing request query request



Get all contacts from the phone book and upload to server but got the following error.

Add image description here FormData

 Enter image description here

Tested code

pass file list contact thumbnail

 ] const path = con.thumbnailPath
body.append (& # 39; image & # 39 ;, {
uri: path,
type: & # 39; image / jpeg & # 39 ;,
name: & # 39; photo.jpg & # 39 ;,
type: & # 39; multipart / form data & # 39;
})

Tested code

pass file url contact thumbnail without "file: //"

  const path = con.thumbnailPath.replace (& # 39; file: // & # 39 ;, & # 39; & # 39;)
body.append (& # 39; image & # 39 ;, {
uri: path,
type: & # 39; image / jpeg & # 39 ;,
name: & # 39; photo.jpg & # 39 ;,
type: & # 39; multipart / form data & # 39;
})

Tested Code

Check file exists on the path or not using react-native-fs

  if (con.thumbnailPath! = & # 39; & # 39; ) {
la isExist = RNFS.exists (con.thumbnailPath)
if (isExist) {
const path = con.thumbnailPath.replace (& # 39; file: // & # 39 ;, & # 39; & # 39;)
console.log ("exists", path)
body.append (& # 39; image & # 39 ;, {
uri: path,
type: & # 39; image / jpeg & # 39 ;,
name: & # 39; photo.jpg & # 39 ;,
type: & # 39; multipart / form data & # 39;
})
}
}

Request

  download (url, {
method: & # 39; POST & # 39 ;,
headings: {
"Authorization": the token,
& # 39; token & # 39 ;: token
}
body: params
})
.then ((res) => res.json ())
.then ((json) => {
console.log ("RESPONSE: -", json)
if (json.response [0] .status == & # 39; false & # 39;) {
la msg = json.response [0] .response_msg
callback (new error (msg), json.response [0])
}
otherwise {
callback (null, json.response [0])
}
})
.catch ((err) => {
console.log (err)
callback (error, zero)
})


Source link