uploading image + optional tags via HTTP POST

by Amit » Fri, 30 Apr 2010 13:42:00 GMT


Sponsored Links
 i,

I am a newbie to Android development; and I want to upload an image
(NOT an image file on the device, but a frame from a camera preview)
to a web-server. I searched around and got a snippet of code that can
be used to upload a byte array. This is the code:

public void uploadImage(final byte[] data) {
// spawn off a new thread to do the image uploading
new Thread(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
Log.d(TAG, "onRun:");
HttpURLConnection conn = null;
try {
serverURL = new URL(URL);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
Log.e(TAG, "Malformed URL!");
e.printStackTrace();
}
try {
// open up a connection with the server
conn = (HttpURLConnection)
serverURL.openConnection();

// set up the conection
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection",
"Keep-Alive");

// now transfer the byte-stream
DataOutputStream ostream = new
DataOutputStream(conn.getOutputStream());
ostream.write(data);
ostream.flush();
ostream.close();

} catch (IOException e) {
// TODO Auto-generated catch block
Log.e(TAG, "No response from server!");
e.printStackTrace();
} finally {
conn.disconnect();
}

// wait for server response
try {
BufferedReader reader = new
BufferedReader(
new
InputStreamReader(conn.getInputStream())
);
String response;
while ((response = reader.readLine())
!= null ) {
Log.d("server response: ",
response);
}
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e



Other Threads

1. adb over wifi

Hi,

has anyone managed to connect to a device with adb over a wifi connection? I'd
like to stop plugging the device in and out if possible. Hackish solutions are
welcome too.

--
  Olivier

-- 

2. Not able to port Libltdl on Android

Hi All ... I am trying to port Libltdl library ... I refered to the
post

http://www.mail-archive.com/android-freerun...@android.koolu.org/msg00334.html


   I have a small issue .  I hope it is not wrong to ask your guidance
to solve the same.  When I try to build the given libltdl in Froyo
Android , It is throwing many errors . We tried to build the same code
using NDK Crystax too . Again the same errors are surfacing . I am not
able to figure out why the errors are caused . Could you please have a
look at the log below and offer some advice ? In your post ,you
mentioed that
Then under that is a directory called android,

which contains the config.h and other android build specific files.


What are the "other android build specific files you are talking
about ? Am I missing something else here ?  Your Help will be greatly
appreciated as we need the Libltdl up and running on Android very
badly .


cet...@ceteam-laptop:~/froyo_x86_source/froyo-x86$ sudo make iso_img
TARGET_PRODUCT=generic_x86
[sudo] password for ceteam:
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.2
TARGET_PRODUCT=generic_x86
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=x86
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=MASTER
============================================
build/core/base_rules.mk:108: user tag on app CustomLibraryClient at
packages/apps/client - add your app to core.mk instead
find: `ethernet/java': No such file or directory
find: `ethernet/java': No such file or directory
build/core/base_rules.mk:108: user tag on app LIME at packages/apps/
LIME - add your app to core.mk instead
build/core/base_rules.mk:108: user tag on app FileManager at packages/
apps/Filemanager - add your app to core.mk instead
build/core/base_rules.mk:108: user tag on app Hello at packages/apps/
hello - add your app to core.mk instead
build/core/base_rules.mk:69: unusual tags systembuilder on badblocks
at external/e2fsprogs/misc
Install: out/target/product/generic_x86/system/app/Mms.apk
target  C: libltdl <= external/libltdl/ltdl.c
external/libltdl/ltdl.c: In function 'rpl_memcpy':
external/libltdl/ltdl.c:392: warning: pointer of type 'void *' used in
arithmetic
external/libltdl/ltdl.c:392: warning: dereferencing 'void *' pointer
external/libltdl/ltdl.c:392: warning: pointer of type 'void *' used in
arithmetic
external/libltdl/ltdl.c:392: warning: dereferencing 'void *' pointer
external/libltdl/ltdl.c:392: error: invalid use of void expression
external/libltdl/ltdl.c: At top level:
external/libltdl/ltdl.c:564: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'rpl_argz_append'
external/libltdl/ltdl.c:569: error: expected identifier or '(' before
'{' token
external/libltdl/ltdl.c:602: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'rpl_argz_create_sep'
external/libltdl/ltdl.c:606: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'rpl_argz_create_sep'
external/libltdl/ltdl.c:611: error: expected identifier or '(' before
'{' token
external/libltdl/ltdl.c:665: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'rpl_argz_insert'
external/libltdl/ltdl.c:669: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'rpl_argz_insert'
external/libltdl/ltdl.c:674: error: expected identifier or '(' before
'{' token
external/libltdl/ltdl.c:857: error: 'LTDL_OBJDIR' undeclared here (not
in a function)
external/libltdl/ltdl.c: In function 'presym_init':
external/libltdl/ltdl.c:1942: warning: unused parameter 'loader_data'
external/libltdl/ltdl.c: In function 'presym_exit':
external/libltdl/ltdl.c:1983: warning: unused parameter 'loader_data'
external/libltdl/ltdl.c: In function 'presym_open':
external/libltdl/ltdl.c:2029: warning: unused parameter 'loader_data'
external/libltdl/ltdl.c: In function 'presym_close':
external/libltdl/ltdl.c:2079: warning: unused parameter 'loader_data'
external/libltdl/ltdl.c: In function 'presym_sym':
external/libltdl/ltdl.c:2089: warning: unused parameter 'loader_data'
external/libltdl/ltdl.c: At top level:
external/libltdl/ltdl.c:2144: error: expected '=', ',', ';', 'asm' or
'__attribute__' before '*' token
external/libltdl/ltdl.c:2174: warning: 'struct direct' declared inside
parameter list
external/libltdl/ltdl.c:2174: warning: its scope is only this
definition or declaration, which is probably not what you want
external/libltdl/ltdl.c: In function 'tryall_dlopen_module':
external/libltdl/ltdl.c:2479: warning: implicit declaration of
function 'sprintf'
external/libltdl/ltdl.c:2479: warning: incompatible implicit
declaration of built-in function 'sprintf'
external/libltdl/ltdl.c: In function 'argzize_path':
external/libltdl/ltdl.c:2614: error: 'error_t' undeclared (first use
in this function)
external/libltdl/ltdl.c:2614: error: (Each undeclared identifier is
reported only once
external/libltdl/ltdl.c:2614: error: for each function it appears in.)
external/libltdl/ltdl.c:2614: warning: statement with no effect
external/libltdl/ltdl.c:2614: error: expected ';' before 'error'
external/libltdl/ltdl.c:2620: error: 'error' undeclared (first use in
this function)
external/libltdl/ltdl.c:2620: warning: implicit declaration of
function 'rpl_argz_create_sep'
external/libltdl/ltdl.c:2624: error: 'ENOMEM' undeclared (first use in
this function)
external/libltdl/ltdl.c: In function 'foreach_dirinpath':
external/libltdl/ltdl.c:2678: warning: comparison between signed and
unsigned
external/libltdl/ltdl.c: In function 'find_file_callback':
external/libltdl/ltdl.c:2724: error: 'FILE' undeclared (first use in
this function)
external/libltdl/ltdl.c:2724: error: 'pfile' undeclared (first use in
this function)
external/libltdl/ltdl.c:2724: error: invalid operands to binary *
external/libltdl/ltdl.c:2724: error: expected expression before ')'
token
external/libltdl/ltdl.c:2724: error: invalid operands to binary *
external/libltdl/ltdl.c:2724: warning: statement with no effect
external/libltdl/ltdl.c:2731: warning: implicit declaration of
function 'fopen'
external/libltdl/ltdl.c:2731: error: assignment of read-only location
external/libltdl/ltdl.c:2733: warning: initialization discards
qualifiers from pointer target type
external/libltdl/ltdl.c:2721: warning: unused parameter 'data2'
external/libltdl/ltdl.c: At top level:
external/libltdl/ltdl.c:2746: error: expected '=', ',', ';', 'asm' or
'__attribute__' before '*' token
external/libltdl/ltdl.c:2751: error: expected identifier or '(' before
'{' token
external/libltdl/ltdl.c: In function 'find_handle_callback':
external/libltdl/ltdl.c:2763: warning: unused parameter 'ignored'
external/libltdl/ltdl.c: In function 'load_deplibs':
external/libltdl/ltdl.c:2801: warning: unused parameter 'deplibs'
external/libltdl/ltdl.c: In function 'try_dlopen':
external/libltdl/ltdl.c:3082: warning: assignment discards qualifiers
from pointer target type
external/libltdl/ltdl.c:3109: error: 'FILE' undeclared (first use in
this function)
external/libltdl/ltdl.c:3109: error: 'file' undeclared (first use in
this function)
external/libltdl/ltdl.c:3109: error: invalid operands to binary *
external/libltdl/ltdl.c:3109: warning: statement with no effect
external/libltdl/ltdl.c:3133: warning: comparison between signed and
unsigned
external/libltdl/ltdl.c:3135: warning: implicit declaration of
function 'isalnum'
external/libltdl/ltdl.c:3158: warning: implicit declaration of
function 'find_file'
external/libltdl/ltdl.c:3158: warning: statement with no effect
external/libltdl/ltdl.c:3165: warning: statement with no effect
external/libltdl/ltdl.c:3185: warning: statement with no effect
external/libltdl/ltdl.c:3201: warning: implicit declaration of
function 'fclose'
external/libltdl/ltdl.c:3207: warning: implicit declaration of
function 'feof'
external/libltdl/ltdl.c:3209: warning: implicit declaration of
function 'fgets'
external/libltdl/ltdl.c:3277: warning: assignment discards qualifiers
from pointer target type
external/libltdl/ltdl.c: In function 'lt_dlopenext':
external/libltdl/ltdl.c:3454: warning: assignment discards qualifiers
from pointer target type
external/libltdl/ltdl.c:3468: error: the address of 'archive_ext' will
always evaluate as 'true'
external/libltdl/ltdl.c: In function 'lt_argz_insert':
external/libltdl/ltdl.c:3531: error: 'error_t' undeclared (first use
in this function)
external/libltdl/ltdl.c:3531: warning: statement with no effect
external/libltdl/ltdl.c:3531: error: expected ';' before 'error'
external/libltdl/ltdl.c:3533: error: 'error' undeclared (first use in
this function)
external/libltdl/ltdl.c:3533: warning: implicit declaration of
function 'rpl_argz_insert'
external/libltdl/ltdl.c:3537: error: 'ENOMEM' undeclared (first use in
this function)
external/libltdl/ltdl.c: In function 'lt_argz_insertdir':
external/libltdl/ltdl.c:3580: error: argument 'dp' doesn't match
prototype
external/libltdl/ltdl.c:2174: error: prototype declaration
external/libltdl/ltdl.c:3593: error: dereferencing pointer to
incomplete type
external/libltdl/ltdl.c:3593: error: request for member 'd_name' in
something not a structure or union
external/libltdl/ltdl.c:3593: error: dereferencing pointer to
incomplete type
external/libltdl/ltdl.c:3593: error: request for member 'd_namlen' in
something not a structure or union
external/libltdl/ltdl.c:3593: error: invalid operands to binary +
external/libltdl/ltdl.c:3593: warning: assignment discards qualifiers
from pointer target type
external/libltdl/ltdl.c:3598: error: dereferencing pointer to
incomplete type
external/libltdl/ltdl.c:3598: error: request for member 'd_name' in
something not a structure or union
external/libltdl/ltdl.c:3609: error: dereferencing pointer to
incomplete type
external/libltdl/ltdl.c:3609: error: request for member 'd_name' in
something not a structure or union
external/libltdl/ltdl.c:3618: error: dereferencing pointer to
incomplete type
external/libltdl/ltdl.c:3618: error: request for member 'd_name' in
something not a structure or union
external/libltdl/ltdl.c:3628: error: dereferencing pointer to
incomplete type
external/libltdl/ltdl.c:3628: error: request for member 'd_name' in
something not a structure or union
external/libltdl/ltdl.c: In function 'list_files_by_dir':
external/libltdl/ltdl.c:3646: error: 'DIR' undeclared (first use in
this function)
external/libltdl/ltdl.c:3646: error: 'dirp' undeclared (first use in
this function)
external/libltdl/ltdl.c:3646: error: invalid operands to binary *
external/libltdl/ltdl.c:3646: warning: statement with no effect
external/libltdl/ltdl.c:3654: warning: implicit declaration of
function 'opendir'
external/libltdl/ltdl.c:3654: warning: statement with no effect
external/libltdl/ltdl.c:3659: warning: implicit declaration of
function 'readdir'
external/libltdl/ltdl.c:3659: warning: assignment makes pointer from
integer without a cast
external/libltdl/ltdl.c:3660: error: dereferencing pointer to
incomplete type
external/libltdl/ltdl.c:3660: error: request for member 'd_name' in
something not a structure or union
external/libltdl/ltdl.c:3661: warning: passing argument 4 of
'lt_argz_insertdir' from incompatible pointer type
external/libltdl/ltdl.c:3667: warning: implicit declaration of
function 'closedir'
make: *** [out/target/product/generic_x86/obj/SHARED_LIBRARIES/
libltdl_intermediates/ltdl.o] Error 1


-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. listview with different xml for rows

4. wifi is not disconnecting in suspend mode

5. Support for Atheros AR300x serial chip in Android kernel

6. is there a way to implement screenshot functionality in android

7. Adding permission in framework.