Is there special markup for downloading video and audio in iOS? - php

I'm making an app in ionic phonegap where I'd like to offer streaming and downloading the video and audio files for offline use.
In Desktop and Android, this is easy. All I have to do is link directly to the file and modify the header directives in php to force the download.
In iPhone/iOs, clicking the same link tries to open the file in a player immediately and doesn't download the file. Furthermore, it doesn't actually play the file. It just loads an empty video player.
I've tried googling this and looking it up on SO, but I can only find guides for downloading and storing the file within the app.
Such as: iOS - Download Video
But that's not what I need. I don't want to reinvent the wheel and turn my app into a file manager. I need the phone to store it natively in cameraroll or prompt the user to load the file in whatever app they normally use for offline video.
I did find a user-level guide that shows that this is possible, but it doesn't say how we can make this possible as developers:
http://osxdaily.com/2013/05/28/save-videos-from-mail-ios/
How do I mark up a video link so that iOS knows to download it locally?

Please check File Transfer Cordova plugin to see if it works on you.
http://plugins.cordova.io/#/package/org.apache.cordova.file-transfer
And here goes an example code snippet:
var fileTransfer = new FileTransfer();
var uri = encodeURI("http://some.server.com/example_file.mp4");
fileTransfer.download(
uri,
fileURL,
function(entry) {
console.log("download complete: " + entry.toURL());
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
false, null
);
EDIT:
Sorry for missing "cameraroll" in your question. I believe there's no direct way to save images from your url to your Camera Roll. However there's an indirect way for this. You can possibly load your image on the HTML5 canvas in your app. After that, just save its base64 formatted data_url to your camera roll.
Check this answer for more informations: Save to camera roll from path/URL in PhoneGap

Related

Get file contents after pageload

I have an external resource for my images let's say https://api.domain.com/api/downloads/{file_id}. The file gets downloaded after I visit that page. In this case I want to know the mimetype of the file. file_get_contents() doesn't work because the file is downloaded after I visit the page.
This means that I get HTML as output when I dump the result of file_get_contents(). I don't have any hold on how images are served to my application. So I guess I have to find a solution for this problem.
Is there a way to get the mimetype of a file after the page is loaded and it downloaded the file? If something I just wrote is not clear enough please let me know then I try to explain it further. Thanks in advance.
Some more detailed information:
I am currently creating an EML export from data from an external API from Genesys. This is pure PHP and thus I can’t make use of any client-side code like Javascript. The inline images in the body don’t show on in the EML export email body. I think this is because Genesys saves those images somewhere on their side. The image is not directly available from the URL they gave to me, because when I visit that page the page downloads a file but it is not directly served on that page.
To show the images inside the email body I want to encode them to base64 and change the src of the image to the base64 encoded image. To do so I need to know the filetype which I can’t get as described above.
Did you try with the onload property on the <img /> tag ?
<img src="w3html.gif" onload="loadImage()" width="100" height="132">
<script>
function loadImage() {
alert("Image is loaded");
}
</script>
https://www.w3schools.com/tags/ev_onload.asp
You will need to use javascript as the image is on a remote server and loaded on client side

Nodejs upload images to other server API

I was wondering if any one can help with following issue.
I have an Api with node/express for image uploads
server1
var upload = multer({ dest: 'uploads/'})
app.post('/api/upload', upload.single('file'), function(req, res, next) {
if (req.file && req.file.path) {
//used to have imgur upload
//imgur.uploadFile(req.file.path)
// .then(function (json) {
//});
}
});
server2
I have PHP Api for image uploads as well which I have set up for self-hosting using pictshare. I want to redirect file uploads to new API by redirecting uploads to PHP Api server.
Have tried multer, multiparty, needle, request and various other methods... but somehow couldn't figure out.
Is there way to direct multer to new destination?
File is being saved in uploads/ folder, maybe better would be to upload/direct that file to new server and return new url from server2 ?
Looked around for pipelining upload images, with not much luck..
note: server1 api is being used by mobile app so wouldn't want to release app update if it can be handled from server side.
To upload a file (image or whatever) you need to have it in your drive first (or in memory, but I will tackle the drive case first). Then you can read it and send it.
The APIs that receive files use to receive forms. Usually they expect to receive a form where the attachment comes as a file field.
Here you can see a working example uploading an existing file in my drive to an external API by using the 'superagent' library for Node.
const
fs = require('fs'),
agent = require('superagent');
const stream = fs.createReadStream('path/to/downloaded/file');
agent.post(`urlOfApi/uploadFileEndpoint`)
.type('form')
.attach('file', stream.path);

How to paste image in chrome, then upload it to a server with PHP

I actually want to upload an image to a server.
To achieve this, i want the user just paste the image into chrome (the image is a print screen in fact), and then i post the stream to a php page, convert the stream as an image, and then upload it.
How can i achieve this web application ?
Today i have develop some differents parts :
I used this script, and i create the Upload.php page which gets the post variable and try to Create and image.
The problem i have, is that when i post the data, i only get a blob. I would like to get a base64 stream.
Can you help me ?
Thanks in advance.
I'm not sure why you are specifically looking for a "base 64 stream". If you are sending the Blob to your server via ajax, as far as your server is concerned, it's a file. Treat it no different than any other upload server-side. A Blob is a File without a name property. That's perhaps a bit overly-simplistic, but my point is that, again, this is really nothing more than a file as far as your server knows.
Assuming you are sending a multipart-encoded request, I'd like to point out that most user agents will set the filename property of the item's Content-Disposition header in the request to "blob" when the item you are uploading is a Blob instead of a file. It is possible to change this value in some browsers via the 3rd argument in FormData's append method, but I wouldn't rely on this just yet.
Also note that, if you are interested in a library that handles all of this already, I maintain, Fine Uploader which natively supports uploading images via paste in Chrome.
To answer this old question: Posting an image from clipboard with chrome is pretty much the same as posting a dropped file - except that the image/blob doesn't have the properties "name" and "lastModified".
var entry = items[i].webkitGetAsEntry();
if (!entry) entry = items[i].getAsFile();
if (entry instanceof Blob) /** CHROME pastet Bilder als Blob **/
{
entry.isFile = true;
entry.lastModifiedDate = new Date();
entry.name = ""+new Date().getTime()+"."+entry.type.split('/')[1];
}
if (entry.isFile)
{
//handle dropped file
}

Sending an audio file path to email and there by playing the audio in jwplayer when clicked on link

One of my friend sent me an email. It contains a path to audio file.
When i click on the link the audio starts playing (only if it is .mp3 format) in chrome.
This is not the case every time A user may send any kind of format Ex: aac,m4a etc.
So i would like to play the audio in a jwplayer
On clicking the url the audio must be able to play in the browser using jwplayer.
The path to the audio file is bitle generated short url.
I downloaded jwplayer files and source code from http://www.longtailvideo.com/players/jw-flv-player/ and i set up my player accordingly to document. But still facing the problem
Kindly give suggestions.
JWPlayer is nice but it lacks a good interface. I have been able to embed jwplayer into prettyphoto and that has solved a lot of issues for me.
There is an article that describes how to do this located at http://forums.no-margin-for-errors.com/discussion/5671/how-to-integrate-jwplayer-in-prettyphoto-with-flash-and-html5/p1
Once you get that working my suggestion would be for the url to contain GET vars that include the filename to be played. Use PHP to create an href that will trigger prettyphoto/jwplayer to open and play the file.
Also, the instructions on the link I gave you did not work for me. I had to modify them but here is the code that got it to work:
case 'jwplayer':
pp_dimensions = _fitToViewport(movie_width,movie_height); // Fit item to viewport
controlbar_height = 29; //Allow for JWplayer's bar
pp_dimensions['height']+=controlbar_height;pp_dimensions['contentHeight']+=controlbar_height;pp_dimensions['containerHeight']+=controlbar_height;
jwplayer_settings = {flashplayer: '/jwplayer/player.swf', controlbar: 'bottom', skin: '/jwplayer/jwplayer_skin.zip', autostart: true, id: 'jwplayer1'};
jwplayer_settings.width = pp_dimensions['width'];
jwplayer_settings.height= pp_dimensions['height'];
jwplayer_settings.file = pp_images[set_position];
skipInjection = true;
/* include jwplayer JS embedder */
$.getScript('/jwplayer/jwplayer.js', function() {
jwplayer("pp_full_res").setup(jwplayer_settings);
_showContent();
});
break;

Provide file download webpage without server side code

Lets say i have this string "something1,something2" and i want to download it as "text.csv", without opening new window (pop up) how could i do this from a webpage. can i dot it in JS without using this:
window.open('data:text/csv;charset=utf-8,' + str);
or do i have to use PHP for this ?
What you want to do is a bit unconventional, but it is possible.
Take a look at Downloadify. It's a JavaScript library that leans on Flash to create a file on the client side and present the file download dialog.
David Walsh has some good demos and info too on his blog.
While limited, there is also http://en.wikipedia.org/wiki/Data_Uri
So this as a url would open an image
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==
You could have javascript open this url to trigger the download
A CSV example
data:text/csv,field1%2Cfield2%0Afoo%2Cbar%0Agoo%2Cgai%0A
Just copy/paste either of those into your browser to see them work. Browser support is limited.
IE 8 for example has a 32KiB limit

Categories