I've ran into this problem where if I try to use "localhost:3000/photo" as my url for the imageview in xcode I don't get an image, but if I use a url where it doesn't url rewrite like "www.somesite.com/image.png" then the image shows up. I believe it might be the way I'm saving to serving the image in node. When I hit my intended url (localhost:3000/photo) the correct image appears on the page. I feel like it should download if I'm serving it right. Let me know what you think.
var imgURL: NSURL = NSURL(string: tableImages[indexPath.row])!
let request: NSURLRequest = NSURLRequest(URL: imgURL)
NSURLConnection.sendAsynchronousRequest(
request, queue: NSOperationQueue.mainQueue(),
completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -> Void in
if error == nil {
cell.imageCell.image = UIImage(data: data)
}
})
Node
var express = require('express');
var router = express.Router();
var util = require("util");
var fs = require("fs");
router.get('/', function(req, res) {
res.sendfile("./upload/d0a73ef5f25219955ae8c480a2bbd6dc.jpg");
});
module.exports = router;
I'm using multer to save
app.use(multer({dest: "./upload/"}));
My uploading route
router.post("/upload", function(req, res, next){
if (req.files) {
console.log(util.inspect(req.files));
if (req.files.myFile.size === 0) {
return next(new Error("No file selected"));
}
fs.exists(req.files.myFile.path, function(exists) {
if(exists) {
res.end("file");
} else {
res.end("no file");
}
});
}
});
Here are some screen shots while debugging