Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8639057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:54:08+00:00 2026-06-12T10:54:08+00:00

The application I’m working uses an API developed by another team. I’m working on

  • 0

The application I’m working uses an API developed by another team. I’m working on Titanium 2.1.2 and I’m trying to upload a photo using said API. I’m using Appcelerator’s HTTPClient to make the request. Here’s my code:

    var url = 'http://api.veramiko.com/albums/' + album.veramiko_id + '/photos';
    var photo = imageView.toBlob();

    var args = { //parameters sent to post photo
        file : photo,
        description : descriptionText
    };

    var client = Ti.Network.createHTTPClient({
        onload : function(e){
            Ti.API.info(this.responseText); //Print the result
        },
        onerror : function(e){
            Ti.API.error(this.responseText); //Print the result
        },
        timeout : 60000
    });
    client.open('POST', url);
    client.setRequestHeader('Authorization', 'Bearer ' + token);
    client.setRequestHeader('Content-type', "multipart/form-data");
    client.send(args);

Token is a variable we use to authorize any requests made to the server. I thought that by only converting the image from the ImageView into Blob would be enough to send the photo, but the photo isn’t uploaded. The post is created with the description but the photo isn’t sent properly.

Do I need to add something else? Is it right to send the photo as a Blob?

EDIT: I read this link and I tried the following with no result:

    var url = 'http://api.veramiko.com/albums/' + album.veramiko_id + '/photos';
    var boundary = '-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var photo = imageView.toBlob();

    var args = {
        file : photo,
        description : descriptionText.value
    };      

    var contentDisposition = "--" + boundary + "\r\n"; 
    contentDisposition += "Content-Disposition: form-data; name=\"file\";";
    contentDisposition += "filename=\"" + imageView.image + "\"\r\n\";";
    contentDisposition += "Content-Type: application/octet-stream\r\n\r\n";

    var fullContent = contentDisposition + photo  + "\r\n--" + boundary + "--";

    alert(JSON.stringify(args));
    var token = JSON.parse(Ti.App.Properties.getString('loggedUser', 'No existe')).networks[0].token;
    var client = Ti.Network.createHTTPClient({
        onload : function(e){
            Ti.API.info(this.responseText); //Print the result
        },
        onerror : function(e){
            Ti.API.error(this.responseText); //Print the result
        },
        timeout : 60000
    });
    client.open('POST', url);
    client.setRequestHeader('Authorization', 'Bearer ' + token);
    client.setRequestHeader('Content-Type', "multipart/form-data; boundary=\"" + boundary + "\"");
    client.setRequestHeader('Connection', 'close');
    client.send(fullContent);

I tried to wrap the file with a Content-Disposition and Content-Type header with no result.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:54:11+00:00Added an answer on June 12, 2026 at 10:54 am

    I finally found a way to solve this. Please refer to the following link.

    This is how my code looked in the end:

        // I put the contents of my image into a variable
    var f = imageHolder.toImage();
        // I create a random name for the image
    var tmpName = (new Date()).getTime().toString() + '.png';
        // I create a folder where I will store the photo temporally
    var g = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'picturesToUpload');
    if (!g.exists()) {
        // If the directory doesn't exist, make it
        g.createDirectory();
    };
    var photo = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'picturesToUpload', tmpName);
        // write the contents of the image into the file
    photo.write(f);
        // I create my url with the albumId where I'll upload the picture
    var url = 'http://api.veramiko.com/albums/' + albumId + '/photos';
    var args = {
        file : photo.read(), // I read the contents of the file
        description : ''
    }
    var token = JSON.parse(Ti.App.Properties.getString('loggedUser', 'No existe')).networks[0].token;
    var client = Ti.Network.createHTTPClient({
        onload : function(e){
            Ti.API.info('Info received from the uploading: ' + this.responseText);
        },
        onerror : function(e){
            Ti.API.debug('Error: ' + this.responseText);
        },
            timeout : 60000
    });
    client.open('POST', url);
        // these headers are important
    client.setRequestHeader('enctype', 'multipart/form-data');
    client.setRequestHeader('Content-Type', 'image/png');
    client.setRequestHeader('Authorization', 'Bearer ' + token);
    client.send(args);
    

    Hope this info helps more people.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Application : HTA (therefore IE) This is an application that uses SendKeys to populate
Application : I am working on one mid-large size application which will be used
The application I'm currently writing is using MVVM with the ViewModel-first pattern. I have
Our application allows users to upload javascript, CSS, and HTML files. We need a
Application uses Entity Framework 4.1 with database first approach. I have in database a
My application want to upload data to backend. Upload functionality available 2 places. One
My application is allowed users to upload jpeg/png files.I must to detect files with
APPLICATION DESCRIPTION : I am a new iPhone developer. I am working on an
Application db connection in web service. i haveto connect the db using that web
Application was built using MS interop, to export .xls to infoPath and vice versa.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.