SlideShare uma empresa Scribd logo
1 de 9
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

Mais conteúdo relacionado

Mais procurados

JS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGJS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGArulkumar
 
Using MongoDB and a Relational Database at MongoDB Day
Using MongoDB and a Relational Database at MongoDB DayUsing MongoDB and a Relational Database at MongoDB Day
Using MongoDB and a Relational Database at MongoDB Dayhayesdavis
 
2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study
2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study
2009 - Microsoft IIS Vs. Apache - Who Serves More - A StudyVijay Prasad Gupta
 
Client-side Website Optimization
Client-side Website OptimizationClient-side Website Optimization
Client-side Website OptimizationRadu Pintilie
 
Web servers (l6)
Web servers (l6)Web servers (l6)
Web servers (l6)Nanhi Sinha
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & IntroductionJerwin Roy
 
Connecting NodeJS & MongoDB
Connecting NodeJS & MongoDBConnecting NodeJS & MongoDB
Connecting NodeJS & MongoDBEnoch Joshua
 
Uniform Resource Locator (URL)
Uniform Resource Locator (URL)Uniform Resource Locator (URL)
Uniform Resource Locator (URL)Mary Daine Napuli
 
MongoDB Command Line Tools
MongoDB Command Line ToolsMongoDB Command Line Tools
MongoDB Command Line ToolsRainforest QA
 
HTTP 완벽가이드 1장.
HTTP 완벽가이드 1장.HTTP 완벽가이드 1장.
HTTP 완벽가이드 1장.HyeonSeok Choi
 
Common Gateway Interface
Common Gateway InterfaceCommon Gateway Interface
Common Gateway InterfaceBalu Masulkar
 

Mais procurados (20)

JS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGJS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTING
 
Using MongoDB and a Relational Database at MongoDB Day
Using MongoDB and a Relational Database at MongoDB DayUsing MongoDB and a Relational Database at MongoDB Day
Using MongoDB and a Relational Database at MongoDB Day
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study
2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study
2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study
 
Apache
ApacheApache
Apache
 
Css
CssCss
Css
 
Client-side Website Optimization
Client-side Website OptimizationClient-side Website Optimization
Client-side Website Optimization
 
Web servers (l6)
Web servers (l6)Web servers (l6)
Web servers (l6)
 
ASP.NET WEB API
ASP.NET WEB APIASP.NET WEB API
ASP.NET WEB API
 
4 Basic PHP
4 Basic PHP4 Basic PHP
4 Basic PHP
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & Introduction
 
Connecting NodeJS & MongoDB
Connecting NodeJS & MongoDBConnecting NodeJS & MongoDB
Connecting NodeJS & MongoDB
 
Intro To Couch Db
Intro To Couch DbIntro To Couch Db
Intro To Couch Db
 
Ajax
AjaxAjax
Ajax
 
Uniform Resource Locator (URL)
Uniform Resource Locator (URL)Uniform Resource Locator (URL)
Uniform Resource Locator (URL)
 
MongoDB Command Line Tools
MongoDB Command Line ToolsMongoDB Command Line Tools
MongoDB Command Line Tools
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 
HTTP 완벽가이드 1장.
HTTP 완벽가이드 1장.HTTP 완벽가이드 1장.
HTTP 완벽가이드 1장.
 
Common Gateway Interface
Common Gateway InterfaceCommon Gateway Interface
Common Gateway Interface
 
Mongodb By Vipin
Mongodb By VipinMongodb By Vipin
Mongodb By Vipin
 

Destaque

Headless fragments in Android
Headless fragments in AndroidHeadless fragments in Android
Headless fragments in AndroidAli Muzaffar
 
Menghitung luas persegi panjang dengan android
Menghitung luas persegi panjang dengan androidMenghitung luas persegi panjang dengan android
Menghitung luas persegi panjang dengan androidAgus Haryanto
 
Sistem Informasi Pelaporan Kebakaran
Sistem Informasi Pelaporan KebakaranSistem Informasi Pelaporan Kebakaran
Sistem Informasi Pelaporan KebakaranAgus Haryanto
 
Langkah-langkah Instalasi software untuk develop aplikasi android
Langkah-langkah Instalasi software untuk develop aplikasi androidLangkah-langkah Instalasi software untuk develop aplikasi android
Langkah-langkah Instalasi software untuk develop aplikasi androidAgus Haryanto
 
Belajar Android Studio Memberi Efek animasi pada Button
Belajar Android Studio Memberi Efek animasi pada ButtonBelajar Android Studio Memberi Efek animasi pada Button
Belajar Android Studio Memberi Efek animasi pada ButtonAgus Haryanto
 
Kenalan Dengan Firebase Android
Kenalan Dengan Firebase AndroidKenalan Dengan Firebase Android
Kenalan Dengan Firebase AndroidAgus Haryanto
 
Introduction to Android Fragments
Introduction to Android FragmentsIntroduction to Android Fragments
Introduction to Android FragmentsSergi Martínez
 
Tutorial Android Membuat Aplikasi senter Flash light
Tutorial Android Membuat Aplikasi senter Flash lightTutorial Android Membuat Aplikasi senter Flash light
Tutorial Android Membuat Aplikasi senter Flash lightAgus Haryanto
 
Android Fast Track CRUD Android PHP MySql
Android Fast Track CRUD Android PHP MySqlAndroid Fast Track CRUD Android PHP MySql
Android Fast Track CRUD Android PHP MySqlAgus Haryanto
 
Belajar Android PHP MySQL Login dengan Volley
Belajar Android PHP MySQL Login dengan VolleyBelajar Android PHP MySQL Login dengan Volley
Belajar Android PHP MySQL Login dengan VolleyAgus Haryanto
 
Belajar Android Membuat Katalog Produk
Belajar Android Membuat Katalog ProdukBelajar Android Membuat Katalog Produk
Belajar Android Membuat Katalog ProdukAgus Haryanto
 
Belajar Android Studio CRUD Data Mahasiswa
Belajar Android Studio CRUD Data MahasiswaBelajar Android Studio CRUD Data Mahasiswa
Belajar Android Studio CRUD Data MahasiswaAgus Haryanto
 
Software requirement and specification
Software requirement and specificationSoftware requirement and specification
Software requirement and specificationAman Adhikari
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisIan Macali
 
requirements analysis and design
requirements analysis and designrequirements analysis and design
requirements analysis and designPreeti Mishra
 

Destaque (17)

Headless fragments in Android
Headless fragments in AndroidHeadless fragments in Android
Headless fragments in Android
 
Android volley
Android volleyAndroid volley
Android volley
 
Menghitung luas persegi panjang dengan android
Menghitung luas persegi panjang dengan androidMenghitung luas persegi panjang dengan android
Menghitung luas persegi panjang dengan android
 
Volley Android
Volley AndroidVolley Android
Volley Android
 
Sistem Informasi Pelaporan Kebakaran
Sistem Informasi Pelaporan KebakaranSistem Informasi Pelaporan Kebakaran
Sistem Informasi Pelaporan Kebakaran
 
Langkah-langkah Instalasi software untuk develop aplikasi android
Langkah-langkah Instalasi software untuk develop aplikasi androidLangkah-langkah Instalasi software untuk develop aplikasi android
Langkah-langkah Instalasi software untuk develop aplikasi android
 
Belajar Android Studio Memberi Efek animasi pada Button
Belajar Android Studio Memberi Efek animasi pada ButtonBelajar Android Studio Memberi Efek animasi pada Button
Belajar Android Studio Memberi Efek animasi pada Button
 
Kenalan Dengan Firebase Android
Kenalan Dengan Firebase AndroidKenalan Dengan Firebase Android
Kenalan Dengan Firebase Android
 
Introduction to Android Fragments
Introduction to Android FragmentsIntroduction to Android Fragments
Introduction to Android Fragments
 
Tutorial Android Membuat Aplikasi senter Flash light
Tutorial Android Membuat Aplikasi senter Flash lightTutorial Android Membuat Aplikasi senter Flash light
Tutorial Android Membuat Aplikasi senter Flash light
 
Android Fast Track CRUD Android PHP MySql
Android Fast Track CRUD Android PHP MySqlAndroid Fast Track CRUD Android PHP MySql
Android Fast Track CRUD Android PHP MySql
 
Belajar Android PHP MySQL Login dengan Volley
Belajar Android PHP MySQL Login dengan VolleyBelajar Android PHP MySQL Login dengan Volley
Belajar Android PHP MySQL Login dengan Volley
 
Belajar Android Membuat Katalog Produk
Belajar Android Membuat Katalog ProdukBelajar Android Membuat Katalog Produk
Belajar Android Membuat Katalog Produk
 
Belajar Android Studio CRUD Data Mahasiswa
Belajar Android Studio CRUD Data MahasiswaBelajar Android Studio CRUD Data Mahasiswa
Belajar Android Studio CRUD Data Mahasiswa
 
Software requirement and specification
Software requirement and specificationSoftware requirement and specification
Software requirement and specification
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
requirements analysis and design
requirements analysis and designrequirements analysis and design
requirements analysis and design
 

Semelhante a Posting Images using Android

Virtual Hosting With Apache and Linux
Virtual Hosting With Apache and LinuxVirtual Hosting With Apache and Linux
Virtual Hosting With Apache and LinuxIresha Rubasinghe
 
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalWordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalChandra Prakash Thapa
 
Make the Web 3D
Make the Web 3DMake the Web 3D
Make the Web 3DAdam Nagy
 
Presentation to SAIT Students - Dec 2013
Presentation to SAIT Students - Dec 2013Presentation to SAIT Students - Dec 2013
Presentation to SAIT Students - Dec 2013Think Media Inc.
 
Windows Hosting Documentation
Windows Hosting DocumentationWindows Hosting Documentation
Windows Hosting Documentationwebhostingguy
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP TutorialLorna Mitchell
 
Image Converter script for PNG to JPG & JPG to PNG.pdf
Image Converter script for PNG to JPG & JPG to PNG.pdfImage Converter script for PNG to JPG & JPG to PNG.pdf
Image Converter script for PNG to JPG & JPG to PNG.pdfBe Problem Solver
 
Content Security Policy (CSP)
Content Security Policy (CSP)Content Security Policy (CSP)
Content Security Policy (CSP)Arun Kumar
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
Getting to The Loop - London Wordpress Meetup July 28th
Getting to The Loop - London Wordpress Meetup  July 28thGetting to The Loop - London Wordpress Meetup  July 28th
Getting to The Loop - London Wordpress Meetup July 28thChris Adams
 

Semelhante a Posting Images using Android (20)

CGI by rj
CGI by rjCGI by rj
CGI by rj
 
Virtual Hosting With Apache and Linux
Virtual Hosting With Apache and LinuxVirtual Hosting With Apache and Linux
Virtual Hosting With Apache and Linux
 
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalWordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
 
Introduction to php web programming - get and post
Introduction to php  web programming - get and postIntroduction to php  web programming - get and post
Introduction to php web programming - get and post
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
Web services tutorial
Web services tutorialWeb services tutorial
Web services tutorial
 
Python cgi programming
Python cgi programmingPython cgi programming
Python cgi programming
 
Gears User Guide
Gears User GuideGears User Guide
Gears User Guide
 
Make the Web 3D
Make the Web 3DMake the Web 3D
Make the Web 3D
 
Copy of cgi
Copy of cgiCopy of cgi
Copy of cgi
 
Presentation to SAIT Students - Dec 2013
Presentation to SAIT Students - Dec 2013Presentation to SAIT Students - Dec 2013
Presentation to SAIT Students - Dec 2013
 
Windows Hosting Documentation
Windows Hosting DocumentationWindows Hosting Documentation
Windows Hosting Documentation
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP Tutorial
 
Image Converter script for PNG to JPG & JPG to PNG.pdf
Image Converter script for PNG to JPG & JPG to PNG.pdfImage Converter script for PNG to JPG & JPG to PNG.pdf
Image Converter script for PNG to JPG & JPG to PNG.pdf
 
Content Security Policy (CSP)
Content Security Policy (CSP)Content Security Policy (CSP)
Content Security Policy (CSP)
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Web Services Tutorial
Web Services TutorialWeb Services Tutorial
Web Services Tutorial
 
contentDM
contentDMcontentDM
contentDM
 
Introduction To CodeIgniter
Introduction To CodeIgniterIntroduction To CodeIgniter
Introduction To CodeIgniter
 
Getting to The Loop - London Wordpress Meetup July 28th
Getting to The Loop - London Wordpress Meetup  July 28thGetting to The Loop - London Wordpress Meetup  July 28th
Getting to The Loop - London Wordpress Meetup July 28th
 

Último

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 

Último (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

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