2

I want to know if the android upload service can work like this, I need to put the image in a JSON array so that the string I'm sending is structured like this:

{"ArchivoItem":["ArchivoImg":"**>>IMAGE GOES HERE<<**", "ArchivoNombre":"cedula", "ArchivoExtension":"jpg"]}

and I'm wondering if the android upload service would work for this purpose, for example, I could try like this:

//Creating a multi part request
        new MultipartUploadRequest(this, uploadId, Constants.UPLOAD_URL)
                .addArrayParameter("ArchivoItem", 
                .addFileToUpload(path, "ArchivoImg"), //Adding file
                .addParameter("ArchivoNombre", "cedula"),
                .addParameter("ArchivoExtension", "jpg")   
                                   ) 
                .setNotificationConfig(new UploadNotificationConfig())
                .setMaxRetries(2)
                .startUpload(); //Starting the upload

would this code create a string like the one above?

1
  • If the image is not too large, encode to base64 and add the base64 to your JSON. Commented Jun 22, 2017 at 16:16

1 Answer 1

1

As said,in the comments, u can encode to base64 and add the base64 to your JSON.

public string ImageToBase64(Image image, 
  System.Drawing.Imaging.ImageFormat format)
{
  using (MemoryStream ms = new MemoryStream())
  {
    // Convert Image to byte[]
    image.Save(ms, format);
    byte[] imageBytes = ms.ToArray();

    // Convert byte[] to Base64 String
    string base64String = Convert.ToBase64String(imageBytes);
    return base64String;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.