我正在尝试上传图像以进行解析,然后将它们附加到模型中,但是每当我上传一个图像时,它都会作为成功上传返回,但 url 包含损坏的图像链接。
例如:
这是上传代码:
getImg: ->
CameraHelper.fileUpload (file) =>
@file = file
forge.file.URL file, (url) =>
@fileURL = url
@$("#uploadImg").addClass("fadeIn").css("background-image", "url(#{url})")
@$("#removeImg").css("display", "inline")
, (content) ->
error "Error finding Image"
, ->
debug "Upload Cancelled"
serverUrl = 'https://api.parse.com/1/files/test.jpg'
parseFile = _.extend @file,
type: "image/jpeg"
name: "share.jpg"
$.ajax
type: "POST",
beforeSend: (request)->
request.setRequestHeader "X-Parse-Application-Id", 'MY-APP-ID'
request.setRequestHeader "X-Parse-REST-API-Key", 'MY-REST-API-ID'
request.setRequestHeader "Content-Type", "image/jpeg"
url: serverUrl
data: parseFile
processData: false
contentType: false
success: (data) ->
alert "File available at: " + data.url
error: (data) ->
obj = jQuery.parseJSON(data)
alert obj
CameraHelper =
fileUpload: (success, err) ->
if APP
forge.file.getImage
saveLocation: "file"
source: "camera"
height: "620px"
width: "620px"
, (file) ->
debug "Successfully uploaded img"
success?(file)
, (content) ->
error "Error in uploading img", content
err?()
else
debug "Sorry that feature is not currently available on the mobile web."
CameraHelper 注意:我正在使用 triggerIO,也被引用:https ://www.parse.com/questions/uploading-files-to-parse-using-javascript-and-the-rest-api无济于事
parseFile 是我要上传的图像