Play framework: file download - android

I try to make a file server to let people download APK file.My server is using Play framework.
the problem is :I always download a "app" file without file extension by PC browser.while using android browser, I always download a "app.bin" file. Is there anything wrong with my code?
test link:test download
public static Result get_app() {
File tmp = new File("Ele.apk");
response().setHeader("Content-Disposition", "attachment; filename=Ele.apk");
response().setContentType("mime/type");
return ok(tmp);
}`

There's no such Content-Type as mime/type or mime/apk as you trying to use it in the sample...
By Wikipedia description APK's Content-Type is application/vnd.android.package-archive and probably this one you should set.
If problem remains try to google what is valid Content-Type for serving these keys.

Related

Statement List Generator and Tester rejects its own generated content

So, basically I'm at step 1 of implementing App Links, I stumbled upon this tool:
https://developers.google.com/digital-asset-links/tools/generator
I give it my domain name, my package name, and I copy paste my App package fingerprint from the play store console. it generate an assetlinks.json file for me, I put it as required at https://my-domain/.well-known/assetlinks.json I test downloads, it works, then I ask this tool to test it, it says
No app deep linking permission found for package_name at my_domain.
my logs indicate that GoogleAssociationService came and took the file (200 status response and the correct number of bytes).
So basically I put the good values, it generates it, and then fetch it and tells me it's wrong, what am I missing ? how can he not be happy with what he generated itself ?
When we came across this issue we have also investigated logs of our proxy and have seen that the "assetlinks.json" file had been successfully downloaded.
In our case, the problem was with Content-Type. In our case, it was the "application/octet-stream" type. According to the documentation, Content-Type should have the type "application/json". We have changed the content type and everything started working as expected.
Check the requirements using the link above and verify that all of them are met by crossing off all potential reasons one by one.
Update 2022-10-30: The provided link is not available anymore. I have used a cached version to fetch the information below:
You must publish your JSON verification file at the following
location:
https://domain.name/.well-known/assetlinks.json
Be sure of the following:
The assetlinks.json file is served with content-type application/json.
The assetlinks.json file must be accessible over an HTTPS connection,
regardless of whether your app's intent filters declare HTTPS as the
data scheme.
The assetlinks.json file must be accessible without any
redirects (no 301 or 302 redirects).
If your app links support
multiple host domains, then you must publish the assetlinks.json file
on each domain. See Supporting app linking for multiple hosts.
Do not
publish your app with dev/test URLs in the manifest file that may not
be accessible to the public (such as any that are accessible only with
a VPN). A work-around in such cases is to configure build variants to
generate a different manifest file for dev builds.

How to upload files using the Google Drive API?

I'm trying to upload a file using the Google Drive api on Android
https://github.com/googlesamples/google-services/tree/master/android/signin/app/src/main/java/com/google/samples/quickstart/signin
I signed up to SignInActivityWithDrive.java in the link above.
But there is no example of uploading a file, downloading a file
I want to know how to upload and download files
Thank you
You can find basic examples of uploading and downloading in the docs.
Uploading
You can send upload requests in any of the following ways:
Simple upload: uploadType=media. For quick transfer of a small file (5 MB or less). To perform a simple upload, refer to
Performing a Simple Upload.
Multipart upload: uploadType=multipart. For quick transfer of a small file (5 MB or less) and metadata describing the file, all in
a single request. To perform a multipart upload, refer to
Performing a Multipart Upload.
Resumable upload: uploadType=resumable. For more reliable transfer, especially important with large files. Resumable uploads
are a good choice for most applications, since they also work for
small files at the cost of one additional HTTP request per upload.
To perform a resumable upload, refer to Performing a Resumable
Upload.
The following example shows how to upload an image using the client libraries:
File fileMetadata = new File();
fileMetadata.setName("photo.jpg");
java.io.File filePath = new java.io.File("files/photo.jpg");
FileContent mediaContent = new FileContent("image/jpeg", filePath);
File file = driveService.files().create(fileMetadata, mediaContent)
.setFields("id")
.execute();
System.out.println("File ID: " + file.getId());
Downloading
Depending on the type of download you'd like to perform — a file, a
Google Document, or a content link — you'll use one of the following
URLs:
Download a file — files.get with alt=media file resource
Download and export a Google Doc — files.export
Link a user to a file — webContentLink from the file resource
An example of a basic download is:
String fileId = "0BwwA4oUTeiV1UVNwOHItT0xfa2M";
OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().get(fileId)
.executeMediaAndDownloadTo(outputStream);
It is 2022 now, and how the Google Drive API works might have changed significantly. I needed to upload a number of large files from a remote server where I have terminal access. This is how I got it working for me:
Use the steps detailed in this link to create a Google Services API (on your local computer) and get the API credentials. An extra step was required before step 3, go to the 'OAuth consent screen' tab on the panel to the left and complete necessary steps required. You have to do this only once. For free google accounts, you'll have to select External as the API type (but you can always keep the api in testing mode to not allow others to use it). Also add the gmail address you wish to use as a test user in this panel. Continue the rest of the steps from the aforementioned link.
From Step 1 you should get a client_secret_XXXXX.json file. Copy it to your remote computer working directory using SCP. Rename the file to client_secrets.json.
pip install pydrive
Import and run the following inside the remote working directory.
from pydrive.auth import GoogleAuth
gauth = GoogleAuth()
gauth.CommandLineAuth()
It will provide you a link that you can use to log into your google account from your local computer. You will get a login key that you will have paste into your remote terminal.
Upload a list of filenames
from pydrive.drive import GoogleDrive
drive = GoogleDrive(gauth)
for filename in filename_list:
## Enter folder ID here.
## You can get the folder Id from your drive link e.g.,
## https://drive.google.com/drive/u/2/folders/1pzschX3uMbxU0lB5WZ6IlEEeAUE8MZ-t
gfile = drive.CreateFile({'parents': [{'id': '1pzschX3uMbxU0lB5WZ6IlEEeAUE8MZ-t'}]})
gfile.SetContentFile(filename)
gfile.Upload() # Upload the file.

how to play video from server?

i want to have a URL like this one (https://www.ooklnet.com/files/381/381489/video.mp4) where when you click it and itll play the video. Thing is this isnt my website or video. i tried my URL which i thought was corrct (http://54.XXX.XXX.238/srv/ProductVideos/lazar108#hotmail.com/s/s_7s.MP4) and it gives me this error:
The requested URL /srv/ProductVideos/lazar108#hotmail.com/s/s_7s.MP4 was not found on this server.
I know for a fact that theres a video in the file path on my server. Proof:
(I need this URL for my android app so i can display the video in the app.)
How can i create a link like this one (https://www.ooklnet.com/files/381/381489/video.mp4)?
I have a Ubuntu 14.04.4 server with AWS EC2!
Any help would be appreciated!!
Thank you!
1) your EC2 has to have security groups open to allow any access to port 80 from the Internet
2) your EC2 has to be running some web server software such as apache
3) apache needs to be configured to serve files, check the document root
4) apache needs to be configured to correctly send mp4 with the right mime type headers see this answer Apache not serving .mp4 files correctly - shows the contents of the file rather than a download prompt
If it is apache ( and not nginx or another web server) you are using check the access log file /var/log/apache2/access.log and the default error log /var/log/apache2/error.log

Can't install APK hosted my own apache server

I've exported an apk from eclipse. I am able to install it without any problem if I copy it to the phone's sd card.
When trying to download via phone's (Galaxy S) browser I get:
"Download unsuccessful".
I have set mime type application/vnd.android.package-archive in the mime.types, restarted apache, still same result.
Also tried :
Download App
Still no luck.
I am able to download and install applications from android market. I suspect that apache is not sending the mime type but this is just a shot in the dark.
How can I fix the problem and be able to install APKs from my web server? (or at least to check if apache sends correct header with mime type)
Any help will be appreciated.
It is better if you add the .apk extension to the apache`s mime config. Take a look at this example:
https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
You can just find the "apk" record and copy the row to the file /etc/mime.types at your server:
application/vnd.android.package-archive apk
Also add this to /etc/apache2/mods-available/mime.conf :
AddType application/vnd.android.package-archive .apk
(There are some other AddType-s, put it after them for sure).
From here on you don't have to put anything for the apk`s mime-type in the tag, the server will handle this. ;)
UPDATE: fixed a bug in AddType line
After all I found the problem thanks in part to CommonsWare advise.
Directory where I put apks for downloads is protected by simpe auth. Phone's browser correctly asks (once) for username/password when browsing it but obviously forgets to send auth info when trying to download the file and that causes 401 Unauthorized.
Solution: remove basic auth from that dir or use another unprotected dir for the apks.
Use curl to test the Web server to make sure it is responding to the HTTP request and returning the proper MIME type. Also, example your server logs to see what error is being logged.
Sometimes you have no access to apache configuration files like /etc/mime.types, especially on the shared servers. You can create file .htaccess (or open if it already exists) in your root directory and add the following string:
AddType application/vnd.android.package-archive .apk
Hope it helps.

apk installation from web page

I'm looking for a sample web page (html code) with a link that will install an apk file directly on my phone by clicking on the link.
Just link to the apk file in the HTML. It couldn't be any simpler.
link
You will have to have "install apps from unknown sources" enabled on your phone.
If you're using ASP.NET, then you'll need to insert the following in your web.config file:
<configuration>
...
<system.webServer>
<staticContent>
<mimeMap fileExtension=".apk"
mimeType="application/vnd.android.package-archive" />
</staticContent>
</system.webServer>
...
</configuration>
Apart from that (as others have said), you just need a normal link:
Click here
and tell your users to enable the Security -> Unknown sources option in Settings.
Extra help for IIS webservers: mbaird's example worked great for me after I added the apk mime type to my IIS webserver. I just put an html file up with that link, but got a 404 error when trying to pull up my test.apk file without the .apk mime entry. As Commonsware said, make sure to allow .apk files in the mime types - this is for sure still necessary on an IIS webserver. You can do this from IIS Manager, select the server, and find "Mime Types", then add an entry.
In .Net this is what I did, I created an .asmx page then a QR code that pointed to it
other wise I kept getting a 404, then this on page load.
protected void Page_Load(object sender, EventArgs e){
ViewState["PreviousPage"] = Request.UrlReferrer;
string filepath = Server.MapPath("AcsMainMenu.apk");
FileInfo droidfile = new FileInfo(filepath);
if (droidfile.Exists)
{
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + droidfile.Name);
Response.AddHeader("Content-Length", droidfile.Length.ToString());
Response.ContentType = "application/vnd.android.package-archive";
Response.TransmitFile(droidfile.FullName);
Response.Flush();
Response.End();
Response.Redirect(ViewState["PreviousPage"].ToString());
}
}

Categories

Resources