无法使用Titanium从相机上传照片

时间:2015-04-21 16:51:45

标签: iphone laravel-5 titanium-mobile titanium-alloy

我对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。

1 个答案:

答案 0 :(得分:0)

Code工作正常。很可能是你的后端问题。与您的网络管理员联系,设置允许POST请求。