Is the android emulator able to upload files to a server - php

I cannot find this anywhere. Is the android emulator able to upload files to a web server? I have been testing for the last hour or so and just realized it may not even be possible. Anyone know?

Yes its possible. It's a little complex to post the code but essentially you'd use File class to find which file you want to upload and then use the apache HttpClient library to do the multiform post. Now if you think it won't work because you don't know what interface the user will use to find the file. There is a way to send an Intent to open a file.
Send an Intent for the user to select a file on Android
But the rest is simply writing the code to perform the upload.

Related

Handling large file uploads and sending to API

I'm stuck wondering what the best solution is to handling large file uploads and sending them to a third-party API. Any pointers on what would be a good solution would be very welcome. Thank you in advance.
The end goal is to send video files to this API - https://docs.bunny.net/reference/manage-videos#video_uploadvideo. The complication is that the files are often large - up to 5GB in size.
I have an existing website built in PHP7 that runs on a LAMP setup on Amazon Lightsail and I want to add a feature for users to upload video files.
Currently I'm uploading the files directly to Amazon S3 using a pre-signed URL. This part is working fine.
But I need to send the files to the API mentioned above. This is where I get stuck!
I think there's two options to explore - (1) find a way to upload directly to the API and skip the S3 upload or (2) continue with uploading to S3 first and then transfer to the API. But I'm not sure if option 1 is even possible or how to do option 2!
With option 1, I'm wondering if there's a way to upload the files from the users directly to the API. If I do this using the regular HTML form upload, then the files are stored temporarily on my server before I can use cURL through PHP to transfer them to the API. This is really time consuming and feels very inefficient. But I don't know how else to send the files to the API without them first being on my server. Maybe there's an option here that I don't know about!
With option 2, I can already upload large files directly to S3 with pre-signed URLs and this process seems to run fine. But I don't know how I would then send the file from S3 to the API. I can use an S3 trigger on new files. But when I looked at Lambda, they have a tiny file size limit. Because my site is hosted on Lightsail, I noticed they have a container option. But I don't know if that can be used for this purpose and if so, how.
Basically, I'm not sure what solution is best, nor how to proceed with that. And maybe there's an option 3 that I'm not aware of!
I would welcome your input.
Many thanks in advance.

Is there away to upload a file through RestFUL API PHP?

I am trying to develop a RESTFUL API call in PHP , where someone will send me a file through the URL to upload
something like:
script.php?file_name=text.txt
is there away I can take text.txt and upload it in PHP?
To clarify:
lets put it this way , what are the ways that a end user could send a file to a PHP program?
The problem with this is that the REST server is not aware of the end user's machine in any way. So, say for instance that your end user is at yoursite.com/upload where they fill out a form with the upload credentials which posts to api.yoursite.com/uploads/do or whatever. As far as the api is concerned, yoursite.com is making the request, not the end user.
So, no. In my opinion there is no safe way to do this. The best alternative would be to upload the file and then HTTP POST the contents to the rest server. That can be tricky if the file is much larger than a few kilobytes, and you would want to do all sorts of security checking before writing the file to the server. The other option would be to use yoursite.com to upload the file to a temporary location and then send some information to the rest server with details on out to CURL the file contents from the first server. Also, can be insecure.
What problem are you trying to solve? What language framework? Can you give more details please?

iPhone app-communicating with servers

Ok. I am a bit of a new developer and haven't done much work with networking (in general, not specifically obj-c). Basically, I need to record a file (I have code to do this), then upload it to a server. I've looked at code to upload to servers and it seems that all I need from the server side of things is a html upload page with a php script, which I have. Another option would be ftp/sftp, although this would be harder to implement. The problem is I need to have authentication for the upload, and preferably have a secure (https) upload, with a username and password. I cannot figure out how to do this. I would also need the server to send back a response to the app.
Also, are their any frameworks to make it easier to upload files? I know there was asihttprequest, but that was discontinued...
What would I need to make the server do to have authentication and authenticated uploads, and be able to return data back to the app? Sorry for such a n00by question, but if you could help that would be great.
Thanks
Check out AFNetworking. I really enjoy doing file downloads and uploads using AFNetworking. The FAQ even gives an example on how to upload a file and download a file. All you need server side is a PHP script to handle a POST file upload.

Upload text as file to another server with PHP

I'm working with a 3rd party API that allows me to upload a file to its database. This file has an specific format, but it's plain text.
What I want to do, is generate the text by myself with a PHP script on my own site and upload it to it's server like a file.
The catch is: I want to do this without have to save a temporary file on my own server and if possible, avoiding the use of cURL.
Thanks in advance.
file_put_contents('http://...', $your_text_file);
However, if the API has http basic auth on it, you'll ned to us a stream context to set all that up.

How to upload images into my remote server with PHP?

I have an android app, that connectos to the remote database with PHP+json
but now, i have to store photos of the users on the remote server. I need to do it storing the URL of the uploaded photo in a row of the USER TABLE. That is not the problem. The problem is that i have not idea about with a given path of a photo, how to upload it into a dir of the remote server of my app?
as i know, i need two things, a function that connects with a PHP and gives to the PHP the photo, and a PHP that receives the photo and uploads it into a dir of the remote database.
Well....¿can someone help me to do it?
I checked a lot of tutorials of doing this with PHP but i can't find a easy one that how to do it with android+php+mysql, all i am finding is too hard for me.
can someone give me the code i need to do it?
thanks
EDIT:
there does not exist a simple function and a simple PHP code that does it? Simple ones, the examples you are giving me are very hard for my skills with this and i can't apply to my android app and my remote server
For the Android part, its just straight Java, and there are loads of examples of using HttpClient to perform file uploads.
How to upload a file using Java HttpClient library working with PHP - strange problem
google search
For the PHP side: http://it.php.net/manual/en/features.file-upload.php (there are a lot of sample)
For the Android side: this article explains hot to use DefaultHttpClient for make and upload via HTTP

Categories