I am developing an app for a course and I am having trouble getting photo upload to work. I didn't have much trouble with other endpoints, but this particular one has me stuck for a week now. Below I have copied the part I have issue with from the iNaturalist API reference.
POST /observation_photos
Auth required. Add photos to observations. This is only for iNat-hosted photos. For adding photos hosted on other services, see POST /observations and PUT /observations/:id.
Params
observation_photo[observation_id]
ID of the observation receiving this photo.
Allowed values: Valid iNat observation ID
file
The photo data.
Allowed values: Multipart photo data
On the front end, I have this form. I made sure I only uploading .png images.
form(role='form', method='post', enctype='multipart/form-data')
div.form-group
input.form-control#image(type='file', accept='png', name='file')
button.btn.btn-default(type='submit') Submit
Here is an excerpt of my code in the attempt to do a POST request following the API instructions.
var express = require('express');
var router = express.Router();
var Client = require('node-rest-client').Client;
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
router.post('/playground', multipartMiddleware, function(req,res){
client = new Client();
var args = {
parameters:{'observation_photo[observation_id]': '1055033', //id for a record
'file' : req.files.file},
headers:{'Authorization': 'Bearer ' + token}
}
client.post('https://inaturalist.org/observation_photos',args, function(data,response){
console.log(response.body);
res.send(data);
});
}
I guess the confusion I have is the file parameter and what form the POST endpoint is expecting for that parameter. Any help will be appreciated.