织梦CMS - 轻松建站从此开始!

沙龙国际_沙龙国际亚洲第一品牌网上娱乐

当前位置: 主页 > 沙龙国际娱乐网址 >

(沙龙国际娱乐网址) iOS,Nodejs图片上传问题

时间:2017-07-16 01:17来源:未知 作者:admin 点击:
ios端代码: let image = goodPhoto[0]let imageData = UIImageJPEGRepresentation(image, Constants.goodPhotoCompressionQuality) if let imageData = imageData { uploadGoodPhotoWithImageData(imageData)}func uploadGoodPhotoWithImageData(imageDa

ios端代码:

let image = goodPhoto[0]
let imageData = UIImageJPEGRepresentation(image, Constants.goodPhotoCompressionQuality)
        
if let imageData = imageData {
   uploadGoodPhotoWithImageData(imageData)
}

func uploadGoodPhotoWithImageData(imageData: NSData) {
    
    let header: [String : String] = [
        "Authorization": "Bearer \(Provider.readToken())"
    ]
    
    let name = "good"
    
    let filename = "good.jpg"
    
    Alamofire.upload(.POST, URLString.uploadURLStr   "/good", headers: nil,
        multipartFormData: {
            multipartFormData in
            
            multipartFormData.appendBodyPart(data: imageData, name: name, fileName: filename, mimeType: "image/jpeg")
        },
        encodingCompletion: {
            encodingResult in
            
            switch encodingResult {
            case .Success(let upload, _, _):
                upload.responseJSON{ response in
                    debugPrint(response)
                }
            case .Failure(let encodingError):
                print("Upload failed with error: \(encodingError)")
            }
        }
    )
}

后台代码:

var express = require("express");
var multer = require('multer');
var app = express();

function handleError(res, err) {
    return res.json(500, err);
};

var storage = multer.diskStorage({
    destination: function (req, file, callback) {
        console.log('b');
        callback(null, './uploads');
    },
    filename: function (req, file, callback) {
        console.log('b');
        callback(null, file.fieldname   '-'   Date.now());
    }
});

// var upload = multer({dest: 'photo/good/'}).single('good');
var upload = multer({storage: storage}).single('good');

exports.uploadGood = function (req, res) {

    upload(req, res, function(err) {
        console.log(err);
        if (err) {
            return handleError(res, err);
        }
        res.json(200, {msg: "File is uploaded"});
    });
};

后台报了500错误,我console.log(err)是这样的

求大神解答

织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
推荐内容