How to send a file to a REST service?

Multi tool use
up vote
0
down vote
favorite
I want to get file in rest service from android.In my code,I send filestream from android via url.If I use like this My entire app is not working by saying...
Logcat
Operation
Fileacces
in contract 'IREST' has a query variable named
stream
of typeSystem.IO.FileStream
, but type
System.IO.FileStream
is not convertible byQueryStringConverter
.
Variables for UriTemplate query values must have types that can
be converted byQueryStringConverter
Here I have post my coding FYR
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FILE_PICKER_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri content_describer = data.getData();
String src = null;
try {
src = getFilePath(UploadActivity.this, content_describer);
} catch (URISyntaxException e) {
e.printStackTrace();
}
Log.d("src is: ", src);
source = new File(src);
fname = source.getName();
Button text = (Button) findViewById(R.id.txt);
text.setText(fname);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
FileOpen.openFile(UploadActivity.this, source);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
Onclick event in action bar icon:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.mybutton) {
new Save().execute();
return true;
}
return super.onOptionsItemSelected(item);
}
SAVE function asynctask
private class Save extends AsyncTask<String,Void,String> {
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
try {
fis=new FileInputStream(source);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ServiceHandler jsonParser = new ServiceHandler();
String fileaccess = ip+"Mobile/rest.svc/Fileacces?stream="+fis+"&filename="+fname;
Log.d("Fileaccess","fileaccess"+fileaccess);
String result = jsonParser.makeServiceCall(fileaccess, ServiceHandler.GET);
Log.i("fileaccess", "result: > " + result);
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
System.out.println(s);
}
}
My rest function in vb.net
Public Function fileacces(ByVal stream As FileStream, ByVal filename As String) As String Implements IREST.fileacces
Dim result = ""
Try
Dim path = "D:XXXYYYECM SourceArchiveEZECMSettingsMonitor" + filename
Dim fileStream = New FileStream(path, FileMode.Create, FileAccess.Write)
stream.CopyTo(fileStream)
fileStream.Dispose()
result = "file uploaded"
Catch ex As Exception
End Try
Return result
End Function

add a comment |
up vote
0
down vote
favorite
I want to get file in rest service from android.In my code,I send filestream from android via url.If I use like this My entire app is not working by saying...
Logcat
Operation
Fileacces
in contract 'IREST' has a query variable named
stream
of typeSystem.IO.FileStream
, but type
System.IO.FileStream
is not convertible byQueryStringConverter
.
Variables for UriTemplate query values must have types that can
be converted byQueryStringConverter
Here I have post my coding FYR
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FILE_PICKER_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri content_describer = data.getData();
String src = null;
try {
src = getFilePath(UploadActivity.this, content_describer);
} catch (URISyntaxException e) {
e.printStackTrace();
}
Log.d("src is: ", src);
source = new File(src);
fname = source.getName();
Button text = (Button) findViewById(R.id.txt);
text.setText(fname);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
FileOpen.openFile(UploadActivity.this, source);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
Onclick event in action bar icon:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.mybutton) {
new Save().execute();
return true;
}
return super.onOptionsItemSelected(item);
}
SAVE function asynctask
private class Save extends AsyncTask<String,Void,String> {
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
try {
fis=new FileInputStream(source);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ServiceHandler jsonParser = new ServiceHandler();
String fileaccess = ip+"Mobile/rest.svc/Fileacces?stream="+fis+"&filename="+fname;
Log.d("Fileaccess","fileaccess"+fileaccess);
String result = jsonParser.makeServiceCall(fileaccess, ServiceHandler.GET);
Log.i("fileaccess", "result: > " + result);
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
System.out.println(s);
}
}
My rest function in vb.net
Public Function fileacces(ByVal stream As FileStream, ByVal filename As String) As String Implements IREST.fileacces
Dim result = ""
Try
Dim path = "D:XXXYYYECM SourceArchiveEZECMSettingsMonitor" + filename
Dim fileStream = New FileStream(path, FileMode.Create, FileAccess.Write)
stream.CopyTo(fileStream)
fileStream.Dispose()
result = "file uploaded"
Catch ex As Exception
End Try
Return result
End Function

add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to get file in rest service from android.In my code,I send filestream from android via url.If I use like this My entire app is not working by saying...
Logcat
Operation
Fileacces
in contract 'IREST' has a query variable named
stream
of typeSystem.IO.FileStream
, but type
System.IO.FileStream
is not convertible byQueryStringConverter
.
Variables for UriTemplate query values must have types that can
be converted byQueryStringConverter
Here I have post my coding FYR
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FILE_PICKER_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri content_describer = data.getData();
String src = null;
try {
src = getFilePath(UploadActivity.this, content_describer);
} catch (URISyntaxException e) {
e.printStackTrace();
}
Log.d("src is: ", src);
source = new File(src);
fname = source.getName();
Button text = (Button) findViewById(R.id.txt);
text.setText(fname);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
FileOpen.openFile(UploadActivity.this, source);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
Onclick event in action bar icon:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.mybutton) {
new Save().execute();
return true;
}
return super.onOptionsItemSelected(item);
}
SAVE function asynctask
private class Save extends AsyncTask<String,Void,String> {
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
try {
fis=new FileInputStream(source);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ServiceHandler jsonParser = new ServiceHandler();
String fileaccess = ip+"Mobile/rest.svc/Fileacces?stream="+fis+"&filename="+fname;
Log.d("Fileaccess","fileaccess"+fileaccess);
String result = jsonParser.makeServiceCall(fileaccess, ServiceHandler.GET);
Log.i("fileaccess", "result: > " + result);
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
System.out.println(s);
}
}
My rest function in vb.net
Public Function fileacces(ByVal stream As FileStream, ByVal filename As String) As String Implements IREST.fileacces
Dim result = ""
Try
Dim path = "D:XXXYYYECM SourceArchiveEZECMSettingsMonitor" + filename
Dim fileStream = New FileStream(path, FileMode.Create, FileAccess.Write)
stream.CopyTo(fileStream)
fileStream.Dispose()
result = "file uploaded"
Catch ex As Exception
End Try
Return result
End Function

I want to get file in rest service from android.In my code,I send filestream from android via url.If I use like this My entire app is not working by saying...
Logcat
Operation
Fileacces
in contract 'IREST' has a query variable named
stream
of typeSystem.IO.FileStream
, but type
System.IO.FileStream
is not convertible byQueryStringConverter
.
Variables for UriTemplate query values must have types that can
be converted byQueryStringConverter
Here I have post my coding FYR
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FILE_PICKER_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri content_describer = data.getData();
String src = null;
try {
src = getFilePath(UploadActivity.this, content_describer);
} catch (URISyntaxException e) {
e.printStackTrace();
}
Log.d("src is: ", src);
source = new File(src);
fname = source.getName();
Button text = (Button) findViewById(R.id.txt);
text.setText(fname);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
FileOpen.openFile(UploadActivity.this, source);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
Onclick event in action bar icon:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.mybutton) {
new Save().execute();
return true;
}
return super.onOptionsItemSelected(item);
}
SAVE function asynctask
private class Save extends AsyncTask<String,Void,String> {
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
try {
fis=new FileInputStream(source);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ServiceHandler jsonParser = new ServiceHandler();
String fileaccess = ip+"Mobile/rest.svc/Fileacces?stream="+fis+"&filename="+fname;
Log.d("Fileaccess","fileaccess"+fileaccess);
String result = jsonParser.makeServiceCall(fileaccess, ServiceHandler.GET);
Log.i("fileaccess", "result: > " + result);
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
System.out.println(s);
}
}
My rest function in vb.net
Public Function fileacces(ByVal stream As FileStream, ByVal filename As String) As String Implements IREST.fileacces
Dim result = ""
Try
Dim path = "D:XXXYYYECM SourceArchiveEZECMSettingsMonitor" + filename
Dim fileStream = New FileStream(path, FileMode.Create, FileAccess.Write)
stream.CopyTo(fileStream)
fileStream.Dispose()
result = "file uploaded"
Catch ex As Exception
End Try
Return result
End Function


edited 14 hours ago


Khaled Lela
2,52622046
2,52622046
asked yesterday


Seyed Ali Fathima
84
84
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
kindly use base 64
like this
public void uploadFile(final String selectedFilePath) {
try {
FileInputStream inputStream = new FileInputStream(selectedFilePath);
byte byteArray = IOUtils.toByteArray(inputStream);
final String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// tvFileName.setText(encoded);
Log.e("File Base 64",encoded);
filebas64=encoded;
}
});
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.e("Error",e.toString());
} catch (IOException e) {
e.printStackTrace();
Log.e("Error",e.toString());
}
}
New contributor
Vignesh Waran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
35 mins ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
kindly use base 64
like this
public void uploadFile(final String selectedFilePath) {
try {
FileInputStream inputStream = new FileInputStream(selectedFilePath);
byte byteArray = IOUtils.toByteArray(inputStream);
final String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// tvFileName.setText(encoded);
Log.e("File Base 64",encoded);
filebas64=encoded;
}
});
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.e("Error",e.toString());
} catch (IOException e) {
e.printStackTrace();
Log.e("Error",e.toString());
}
}
New contributor
Vignesh Waran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
35 mins ago
add a comment |
up vote
0
down vote
kindly use base 64
like this
public void uploadFile(final String selectedFilePath) {
try {
FileInputStream inputStream = new FileInputStream(selectedFilePath);
byte byteArray = IOUtils.toByteArray(inputStream);
final String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// tvFileName.setText(encoded);
Log.e("File Base 64",encoded);
filebas64=encoded;
}
});
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.e("Error",e.toString());
} catch (IOException e) {
e.printStackTrace();
Log.e("Error",e.toString());
}
}
New contributor
Vignesh Waran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
35 mins ago
add a comment |
up vote
0
down vote
up vote
0
down vote
kindly use base 64
like this
public void uploadFile(final String selectedFilePath) {
try {
FileInputStream inputStream = new FileInputStream(selectedFilePath);
byte byteArray = IOUtils.toByteArray(inputStream);
final String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// tvFileName.setText(encoded);
Log.e("File Base 64",encoded);
filebas64=encoded;
}
});
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.e("Error",e.toString());
} catch (IOException e) {
e.printStackTrace();
Log.e("Error",e.toString());
}
}
New contributor
Vignesh Waran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
kindly use base 64
like this
public void uploadFile(final String selectedFilePath) {
try {
FileInputStream inputStream = new FileInputStream(selectedFilePath);
byte byteArray = IOUtils.toByteArray(inputStream);
final String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// tvFileName.setText(encoded);
Log.e("File Base 64",encoded);
filebas64=encoded;
}
});
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.e("Error",e.toString());
} catch (IOException e) {
e.printStackTrace();
Log.e("Error",e.toString());
}
}
New contributor
Vignesh Waran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Vignesh Waran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered yesterday


Vignesh Waran
11
11
New contributor
Vignesh Waran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Vignesh Waran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Vignesh Waran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
35 mins ago
add a comment |
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
35 mins ago
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
35 mins ago
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
35 mins ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238072%2fhow-to-send-a-file-to-a-rest-service%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
EaVSHHePgA4b1 qFP9ow XEWpbIBMiUoES,2kIpH ntY JNLg,YAcAqGy3djRmHPAepN