I am working on an android application, in which we are required to upload an encrypted file to a server using VPN network on a mobile device. I have the method to encrypt the file, but I have no information how to upload a particular file to a remote server. Kindly suggest me some method to upload a particular file to the server. Also suggest me how to calculate the upload time.
Thanks!
Try this code $upload_time = time() - $_SERVER['REQUEST_TIME'];.The result will be in seconds
Related
I programming python server and android client.
program's logic is client send multiple file to server.
I first try C/C++ socket server but receive error. so I change python. because server on raspberry pi.
I have to implement file upload, audio streaming. so I think this logic.
1. Client send http request to server
2. When server receives the request, server create tcp socket and listen.
3. Client receives success response, connect to server and file upload.
Audio streaming will implement similar way.
Is it ok to implement this way? or is there a better way?
Please give me a hint how to implement it.
Ignore socket as much as you for small deployments. They are little more complicated to handle.
Now asuming you want to upload a image file or some other file to a python you can use Flask Upload
Next move on to audio, if you have to upload audio from client to server, than there is no need to stream or stuff, just pass appropriate MIME type during upload.
ALLOWED_AUDIO_EXTENSIONS = set(['wav', 'ogg', 'mp3', ])
def audio_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_AUDIO_EXTENSIONS
if file and audio_file(file.filename):
filename = secure_filename(file.filename)
#perform some application logic with audio files and then save them in file system or call boto3 to save on s3
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('uploaded_file',
filename=filename))
Code is modified from flask examples.
I want to delete image upload to Cloudinary to Android side, on the documentation https://github.com/cloudinary/cloudinary_java/tree/master/cloudinary-android I can't see that.
You can delete the cloudinary image from android client application with the below code:
Cloudinary cloudinary=new Cloudinary(CLOUDINARY_URL)
Map deleteParams = ObjectUtils.asMap("invalidate", true );
cloudinary.uploader().destroy("public_id",deleteParams );
Make sure you have a valid image public_id.
Deleting images requires using a signed authenticated API, the signature is based on your account's api_secret which must be excluded from your client-side code, and therefore should be done on your server-side. So you can make a request from the Android app, which requests the server perform the deletion request.
I'm using vector (It's a Android Matrix client Download link:
https://github.com/vector-im/vector-android). This Vector is using
the https server (https://vector.im and https://matrix.org as home
and identity url's) but i want to connect my local matrix server
using http not https.
For this i edited the strings.xml (id's are vector_im_server_url,
matrix_org_server_url, default_hs_server_url,
default_identity_server_url) file with my local http server.
In this case i'm getting the toast message as "Unable to login :
failed to connect to XXXXXX.XXXXXX.com/XXX.XXX.XXX.XXX (port 8008)
after 15000ms". can anyone help where to change this setting
Note:
Initially i'm not able to access the local matrix server url in my system browser for this i added server details in C:\Windows\System32\drivers\etc\hosts after that i'm able to access it in my browser
I think you missed my answer on #matrix:matrix.org. I tried to connect to your homeserver on port 8448 and 8008 from the public internet and the server was not responding. It looks like you need to open up your firewall on those ports. Please try asking again in #matrix:matrix.org (bearing in mind that the core matrix team are awake on european timezones).
Edit: As per https://vector.im/develop/#/room/#matrix:matrix.org/$147222237811409Apqfi:matrix.org, the server really was inaccessible when we tried to give you support earlier. Glad you've got it sorted now; you should also be using the same HS url for both 'vector' and 'matrix' HS URL otherwise it will try to fall back to using matrix.org for unrecognised users. Thanks for the downvote...
M
By using https server only we can use vector services. So, i changed strings.xml as like this
<string name="vector_im_server_url">https://matrix.org</string>
<string name="matrix_org_server_url">my_local_https_server_url</string>
<string name="default_hs_server_url">my_local_https_server_url</string>
<string name="default_identity_server_url">https://matrix.org</string>
to know these url's open your local https server url in browser. It will show Home Server and Identity Server as shown in the image and paste Identity Server url in vector_im_server_url and default_identity_server_url then Home Server url in matrix_org_server_url and default_hs_server_url
I've stored my .apk file in my rails server. I've set up a route that redirects a given url to a method that essentially sends the file
in my routes.rb file
match '/myApk.apk' to: 'upgradeapk#index'
Upgradeapk_controller.rb file
def index
#filename = '/myApk/myApk.apk'
#tmpfile = 'upgradedApk.apk'
send_file(#filename, :disposition => 'inline', :stream => true, :type=> 'application/vnd.android.package-archive', :file_name => #tmpfile)
end
When i type my sever url and add '/myApk.apk' it starts the downloading process as long as i do it on my a computer. However if i try to do it on my android device it doesn't work. Checking the download lists in my android device browser i notice that the download "job" for the apk is created, however its in an endless loop changing between states "in queue" and "downloading". Nothing ever downloads.
Do I have to set the send_file differently when it comes to making it work on android devices?
----EDIT------
Ok so i've decided to store the files in a dropbox location instead of storing it in my server. If i pass the url for the file directly in my android function for the http request, it works well. The file is found, downloaded and the installation is prompted.
class UpgradeapkController < ApplicationController
def index
android_apk = Androidaplicacion.first (Model to access the table in which i store the apk dropbox url)
route = android_apk.url
redirect_to route
end
end
I've set up my controller to redirect to the given url for the dropbox file. If i try the url (same as before, using the "match" url) in my android browser, this time it downloads. However, if I try it from the android app, its the same as before, it just doesnt download.
So, the "send_file" method seems to not be working if its on the android platform. redirecting to my dropbox url from the controller works on android but only from a browser, not using the http request on my android app. The only way to get it to work in my android app is if I use the dropbox direct link.
Also, I first thought this was because my server was running on https and the certificate its not a valid one. I found a way to bypass the https certification encryption/certificate validation thing on my android app but it didnt work either (it appeared to have succeed in avoiding the validation) but the results ended up been the same. I then ran an instance of my server using http and still same results.
I've a process to send an image to server as per client/end-user wish(pick) from gallery and upload. But the task is to send an image file from an application, even-though user don't have an internet connection and it should send a file when he/she get it(internet connection again/back). I request you people to suggest some idea and it will helpful if I get snippet of code/sample. Thank you!
You can try the following:
Make an android service which gets started when application tries to send files but internet is not available.
Android service will wait for internet connectivity availability.
Store the http url and image uri for every upload request made during this time in SharedPreference.
When network becomes available fetch upload request from shared preference and make request one by one.
Hope this helps.