【发布时间】:2015-04-21 16:51:45
【问题描述】:
我对 Titanium 有一个非常奇怪的问题,我已经搜索了很多资源来解决这个问题,但我就是想不通了。
是这样的: 我想将我用 Iphone 拍摄的照片上传到我的服务器。后端由 PHP/Laravel 制作。
问题: 每次我上传图片钛都会给我错误:HTTP错误。
后端:
$userID = Authorizer::getResourceOwnerId();
$awsLocation = 'lonelylover.s3-website-eu-west-1.amazonaws.com/';
$uploadProfilePic = new AwsUpload('source','posts/','posts/');
$uploadProfilePic->upload();
$posts = DB::table('Posts')->insert(
array(
'user_id'=>$userID,
'Event_id'=>Request::input('event_id'),
'description'=>Request::input('description'),
'status'=>'public',
'source'=>$awsLocation.$uploadProfilePic->getUploadedFile(),
)
);
if($posts){
return Response::json(array('meta'=>array('code'=>200),'data'=>"resource sucesfully created"));
}
钛:
var url = "myurl.com?access_token=abcder898";
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'camera_photo.png');
f.write(args.picture);
var data_to_send = {
event_id: 2,
description:"Upload from titanium",
source:f.read()
};
Ti.API.info(data_to_send);
var xhr = Ti.Network.createHTTPClient({
onload: function(e) {
// this function is called when data is returned from the server and available for use
// this.responseText holds the raw text return of the message (used for text/JSON)
// this.responseXML holds any returned XML (including SOAP)
// this.responseData holds any returned binary data
Ti.API.info(JSON.parse(this.responseText));
alert('success');
},
onerror: function(e) {
// this function is called when an error occurs, including a timeout
Ti.API.info(e.error);
alert('error');
},
timeout:5000 /* in milliseconds */
});
xhr.open("POST", url);
xhr.setRequestHeader('Content-Type','multipart/form-data');
xhr.send(data_to_send);
有没有人可以帮助我解决这个问题,因为我真的没有选择。
Tnx.
【问题讨论】:
-
状态码是什么?
-
@EduardoGomez 我得到一个 405 状态码...我不知道为什么.. 这描述了 405 状态码错误:不允许方法请求行中指定的方法不允许资源由 Request-URI 标识。响应必须包含一个 Allow 标头,其中包含所请求资源的有效方法列表。
-
好的。出现错误:[INFO] 在此服务器上找不到请求的 URL。您要访问的完整 URL 是什么?
-
我访问的 url 位于我的开发环境中,该开发环境在 Virtualbox 上运行,Homestead 安装了 Laravel。
-
尝试另一个 Rest 客户端。即chrome.google.com/webstore/category/apps?hl=en 一点也不熟悉 Laravel。对不起。
标签: iphone laravel-5 titanium-mobile titanium-alloy