Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

cant upload picture from camera with Titanium

$
0
0

I've a really strange problem with Titanium and i've search a lot of sources to solve this issue but i just can't figured it out anymore.

This is the case: I want to upload the picture that i have just took with my Iphone to my server. The back-end is made by PHP / Laravel.

The problem: Everytime i upload the picture titanium gives me the error: HTTP Error.

Back-end:

$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"));
    }
Titanium:
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);
I've literally tried everything i could think of and searched a lot of sources on this forum but also others on the net. Even when i post a simple text to the server it gives me a http error :

405 that means:

Method Not Allowed The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource.

Is there anyone who can help me out with this issue because i seriously out of options.

Tnx.


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>