I'm hosting my application in azure (Web service + file storage service).
I wish to use Fresco (SimpleDraweeView) in my application, the problem is that i can not give a direct url to the user, as the storage in azure is private.
The only thing i can do is to get the image as byte array (using my web service) and foward this byte array back to the android client.
How can one use simpledraweeview with a byte array instead of a direct link?
I have tried to set an endpoint in my webservice where the user is giving me the image id and the endpoint returns back the byte array, i have tried to use this endpoint as the url for the simpledraweeview.setImageUrl method but with no luck.
According to your description, per my experience, it sounds like you need to create a web app as proxy service to access and response the image hosted on Azure File Storgae back to andoird.
Assumption that you are a Java Web developer, I think the simple way is that you can create a Java web app in Azure App Service, then create a Java servlet for the Java web app and refer to the article How to use File Storage from Java to download the image to pipe the stream to http servlet response, please see the sample code below.
private static final String storageConnectionString =
"DefaultEndpointsProtocol=http;" +
"AccountName=your_storage_account_name;" +
"AccountKey=your_storage_account_key";
private CloudFileClient fileClient;
/**
* @see HttpServlet#HttpServlet()
*/
public PipeStream4FileStorage() {
super();
try {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
fileClient = storageAccount.createCloudFileClient();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String dirName = request.getParameter("dir");
String fileName = request.getParameter("file");
OutputStream outStream = response.getOutputStream();
try {
// Get a reference to the file share
CloudFileShare share = fileClient.getShareReference("sampleshare");
//Get a reference to the root directory for the share.
CloudFileDirectory rootDir = share.getRootDirectoryReference();
//Get a reference to the directory that contains the file
CloudFileDirectory sampleDir = rootDir.getDirectoryReference(dirName);
//Get a reference to the file you want to download
CloudFile file = sampleDir.getFileReference(fileName);
//Write the stream of the file to the httpServletResponse.
file.download(outStream);
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (StorageException e) {
e.printStackTrace();
}
}
Note, please see the javadoc for the key function download(OutputStream outStream)
.
Then, you just need to set the image url for SimpleDraweeView like below.
Uri uri = Uri.parse("https://<your-webapp-name>.azurewebsites.net/<servlet-url-mapping-name>?dir=<dir-name>&file=<file-name>");
SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);
draweeView.setImageURI(uri);