0

I have a client written in xcode and I would like to upload the user pic to be stored on the server. The server run node js and I store the uploaded files with gridfs

How should I send the picture in nodejs query. Is it suppose to be binary format of the pic? If so, does this mean - the client should create a binary format of the image in xcode the client should send the binary format as string appended to the url request for node the server stores the string in gridfs the client retrieves the image and parse/present it as jpg/png image?

Liatz
  • 4,997
  • 7
  • 28
  • 33

1 Answers1

0

I would just use an HTTP POST similar to how you would do the same in a web form. Check this post for an example of how to do this with iOS/cocoa.

ios Upload Image and Text using HTTP POST

Once the file gets to your nodejs server, its up to you how you want to handle. If using express framework setup middleware thusly:

/** Form Handling */
app.use(express.bodyParser({
  uploadDir: app.settings.tmpFolder,
  keepExtensions: true
}))
app.use(express.limit('5mb'))

Then you can access the uploaded image with req.files, pre-process and then store in gridfs with your MongoDB module of choice.

Community
  • 1
  • 1
srquinn
  • 10,134
  • 2
  • 48
  • 54