SlideShare a Scribd company logo
Uploading Images in
HTTP Using Android
By Ali Muzaffar
http://alimuzaffar.com
Posting Data over HTTP
When you post data in using HTTP, you have 2 content type
options:
- multipart/form-data
- application/x-www-form-urlencoded
Both formats transfer plain text over http.
The main difference is how the data is formatted.
Posting Data over HTTP
 The default format used when posting data is x-www-
form-urlencoded.
 There is a common misconception that form-data is the
default format.
Format of post using x-www…
 x-www-form-urlencoded posts data using a format
similar to (actually the same as) url parameters. This
is just a standard, the body can contain data in any
format as long as your backend is setup to handle it.
POST /my-api/customer/address/ HTTP/1.1
Host: my-server.com.au
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
NewShipping%5BfirstName%5D=Kiwi&NewShipping%5BlastName%5D=Jones&NewShipping%5Baddress1%5D=
Some+Place&NewShipping%5Baddress2%5D=In+New+Zealand&NewShipping%5Btown%5D=1842%2C+Surfdale
%2C+Waiheke+Island&NewShipping%5Bphone%5D=12345678&NewShipping%5Bcountry%5D=171&ShippingAd
dressOption=1&NewShipping%5Bgender%5D=male&NewShipping%5BbirthdayDay%5D=1&NewShipping%5Bbi
rthdayMonth%5D=2&NewShipping%5BbirthdayYear%5D=1942
Format of post using form-
data Form-data posts data using very structured data format. The body must be in this
format.
 It’s “multipart” because each section can have it’s own headers allowing for different
types of data to be transmitted.
POST /my-api/customer/address/ HTTP/1.1
Host: my-server.com.au
Cache-Control: no-cache
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="products[0][p]"
AT049AA59TWQ
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="products[0][image]”; Content-Type: image/png;
filename=“product_image.png”;
<base64 encoded image>
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="products[0][gift_wrap_num]"
0
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Images and Password
 Base64 encoded.
 Plain HTTP username and password are base 64 encoded
and added to the headers.
 “username:password” is the format (similar to apache
htaccess.
 Key: Authorize
 Value: Basic <Base64>
 Images, by default are Base64 encoded in the form-data
format.
 Content-Type and filename can he optionally specified for
the “part” that contains the image.
Uploading Images Using
Volley
 Volley by default uses application/x-www-form-
urlencoded format.
 Certain services may require a multipart/form-data post.
 Simple MultipartRequest for Google Volley
 We fallback to using direct HTTP, but what do you do if
you’re using Volley?
Uploading images bypassing
Volley
 Reuse your HttpStack implementation, create a new
instance of HttpStack and use it to get your HttpClient.
 Use the HttpClient to build a multipart post.
 Example code here:
 https://gist.github.com/alphamu/7190a8ed0986b5fb8376
Thank you
 MultipartRequest for Google Volley
 https://gist.github.com/alphamu/684d8ae311d95831ce1c
 Sample SslHttpStack implementation and Uploading
images using it.
 https://gist.github.com/alphamu/7190a8ed0986b5fb8376
 Learn more about multipart messages:
 http://en.wikipedia.org/wiki/MIME#Multipart_message
s

More Related Content

What's hot (20)

PDF
JS BASICS JAVA SCRIPT SCRIPTING
Arulkumar
 
PDF
Using MongoDB and a Relational Database at MongoDB Day
hayesdavis
 
PDF
Mongo db basics
Claudio Montoya
 
PDF
2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study
Vijay Prasad Gupta
 
PPT
Apache
NIRMAL FELIX
 
PPT
Css
NIRMAL FELIX
 
PDF
Client-side Website Optimization
Radu Pintilie
 
PPT
Web servers (l6)
Nanhi Sinha
 
PPTX
ASP.NET WEB API
Thang Chung
 
PDF
4 Basic PHP
Jalpesh Vasa
 
PPTX
MongoDB basics & Introduction
Jerwin Roy
 
PPTX
Connecting NodeJS & MongoDB
Enoch Joshua
 
PDF
Intro To Couch Db
Shahar Evron
 
PPT
Ajax
NIRMAL FELIX
 
PPTX
Uniform Resource Locator (URL)
Mary Daine Napuli
 
KEY
MongoDB Command Line Tools
Rainforest QA
 
PPT
Spsl v unit - final
Sasidhar Kothuru
 
PDF
HTTP 완벽가이드 1장.
HyeonSeok Choi
 
PPT
Common Gateway Interface
Balu Masulkar
 
PDF
Mongodb By Vipin
Vipin Mundayad
 
JS BASICS JAVA SCRIPT SCRIPTING
Arulkumar
 
Using MongoDB and a Relational Database at MongoDB Day
hayesdavis
 
Mongo db basics
Claudio Montoya
 
2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study
Vijay Prasad Gupta
 
Apache
NIRMAL FELIX
 
Client-side Website Optimization
Radu Pintilie
 
Web servers (l6)
Nanhi Sinha
 
ASP.NET WEB API
Thang Chung
 
4 Basic PHP
Jalpesh Vasa
 
MongoDB basics & Introduction
Jerwin Roy
 
Connecting NodeJS & MongoDB
Enoch Joshua
 
Intro To Couch Db
Shahar Evron
 
Uniform Resource Locator (URL)
Mary Daine Napuli
 
MongoDB Command Line Tools
Rainforest QA
 
Spsl v unit - final
Sasidhar Kothuru
 
HTTP 완벽가이드 1장.
HyeonSeok Choi
 
Common Gateway Interface
Balu Masulkar
 
Mongodb By Vipin
Vipin Mundayad
 

Viewers also liked (17)

PPTX
Headless fragments in Android
Ali Muzaffar
 
PDF
Android volley
Programming Talents
 
PDF
Menghitung luas persegi panjang dengan android
Agus Haryanto
 
PDF
Volley Android
zezzi Castillo
 
PDF
Sistem Informasi Pelaporan Kebakaran
Agus Haryanto
 
PDF
Langkah-langkah Instalasi software untuk develop aplikasi android
Agus Haryanto
 
PDF
Belajar Android Studio Memberi Efek animasi pada Button
Agus Haryanto
 
PDF
Kenalan Dengan Firebase Android
Agus Haryanto
 
PPT
Introduction to Android Fragments
Sergi Martínez
 
PDF
Tutorial Android Membuat Aplikasi senter Flash light
Agus Haryanto
 
PDF
Android Fast Track CRUD Android PHP MySql
Agus Haryanto
 
PDF
Belajar Android PHP MySQL Login dengan Volley
Agus Haryanto
 
PDF
Belajar Android Membuat Katalog Produk
Agus Haryanto
 
PDF
Belajar Android Studio CRUD Data Mahasiswa
Agus Haryanto
 
PPTX
Software requirement and specification
Aman Adhikari
 
PPTX
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
PPT
requirements analysis and design
Preeti Mishra
 
Headless fragments in Android
Ali Muzaffar
 
Android volley
Programming Talents
 
Menghitung luas persegi panjang dengan android
Agus Haryanto
 
Volley Android
zezzi Castillo
 
Sistem Informasi Pelaporan Kebakaran
Agus Haryanto
 
Langkah-langkah Instalasi software untuk develop aplikasi android
Agus Haryanto
 
Belajar Android Studio Memberi Efek animasi pada Button
Agus Haryanto
 
Kenalan Dengan Firebase Android
Agus Haryanto
 
Introduction to Android Fragments
Sergi Martínez
 
Tutorial Android Membuat Aplikasi senter Flash light
Agus Haryanto
 
Android Fast Track CRUD Android PHP MySql
Agus Haryanto
 
Belajar Android PHP MySQL Login dengan Volley
Agus Haryanto
 
Belajar Android Membuat Katalog Produk
Agus Haryanto
 
Belajar Android Studio CRUD Data Mahasiswa
Agus Haryanto
 
Software requirement and specification
Aman Adhikari
 
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
requirements analysis and design
Preeti Mishra
 
Ad

Recently uploaded (20)

PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Français Patch Tuesday - Juillet
Ivanti
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PDF
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
PDF
Novus-Safe Pro: Brochure-What is Novus Safe Pro?.pdf
Novus Hi-Tech
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Français Patch Tuesday - Juillet
Ivanti
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
Novus-Safe Pro: Brochure-What is Novus Safe Pro?.pdf
Novus Hi-Tech
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Ad

Posting Images using Android

  • 1. Uploading Images in HTTP Using Android By Ali Muzaffar http://alimuzaffar.com
  • 2. Posting Data over HTTP When you post data in using HTTP, you have 2 content type options: - multipart/form-data - application/x-www-form-urlencoded Both formats transfer plain text over http. The main difference is how the data is formatted.
  • 3. Posting Data over HTTP  The default format used when posting data is x-www- form-urlencoded.  There is a common misconception that form-data is the default format.
  • 4. Format of post using x-www…  x-www-form-urlencoded posts data using a format similar to (actually the same as) url parameters. This is just a standard, the body can contain data in any format as long as your backend is setup to handle it. POST /my-api/customer/address/ HTTP/1.1 Host: my-server.com.au Cache-Control: no-cache Content-Type: application/x-www-form-urlencoded NewShipping%5BfirstName%5D=Kiwi&NewShipping%5BlastName%5D=Jones&NewShipping%5Baddress1%5D= Some+Place&NewShipping%5Baddress2%5D=In+New+Zealand&NewShipping%5Btown%5D=1842%2C+Surfdale %2C+Waiheke+Island&NewShipping%5Bphone%5D=12345678&NewShipping%5Bcountry%5D=171&ShippingAd dressOption=1&NewShipping%5Bgender%5D=male&NewShipping%5BbirthdayDay%5D=1&NewShipping%5Bbi rthdayMonth%5D=2&NewShipping%5BbirthdayYear%5D=1942
  • 5. Format of post using form- data Form-data posts data using very structured data format. The body must be in this format.  It’s “multipart” because each section can have it’s own headers allowing for different types of data to be transmitted. POST /my-api/customer/address/ HTTP/1.1 Host: my-server.com.au Cache-Control: no-cache ----WebKitFormBoundaryE19zNvXGzXaLvS5C Content-Disposition: form-data; name="products[0][p]" AT049AA59TWQ ----WebKitFormBoundaryE19zNvXGzXaLvS5C Content-Disposition: form-data; name="products[0][image]”; Content-Type: image/png; filename=“product_image.png”; <base64 encoded image> ----WebKitFormBoundaryE19zNvXGzXaLvS5C Content-Disposition: form-data; name="products[0][gift_wrap_num]" 0 ----WebKitFormBoundaryE19zNvXGzXaLvS5C
  • 6. Images and Password  Base64 encoded.  Plain HTTP username and password are base 64 encoded and added to the headers.  “username:password” is the format (similar to apache htaccess.  Key: Authorize  Value: Basic <Base64>  Images, by default are Base64 encoded in the form-data format.  Content-Type and filename can he optionally specified for the “part” that contains the image.
  • 7. Uploading Images Using Volley  Volley by default uses application/x-www-form- urlencoded format.  Certain services may require a multipart/form-data post.  Simple MultipartRequest for Google Volley  We fallback to using direct HTTP, but what do you do if you’re using Volley?
  • 8. Uploading images bypassing Volley  Reuse your HttpStack implementation, create a new instance of HttpStack and use it to get your HttpClient.  Use the HttpClient to build a multipart post.  Example code here:  https://gist.github.com/alphamu/7190a8ed0986b5fb8376
  • 9. Thank you  MultipartRequest for Google Volley  https://gist.github.com/alphamu/684d8ae311d95831ce1c  Sample SslHttpStack implementation and Uploading images using it.  https://gist.github.com/alphamu/7190a8ed0986b5fb8376  Learn more about multipart messages:  http://en.wikipedia.org/wiki/MIME#Multipart_message s