Releases: adopted-ember-addons/ember-file-upload
2.0.0-beta.28
tldr;
You can stub out endpoints that handle uploads using the upload
mirage helper, and can trigger uploads using the upload
test helper 🏖
To upload a file in mirage:
mirage/config.js
import { upload } from 'ember-file-upload/mirage';
export default function () {
this.post('/photos/new', upload(function (db, request) {
let { type, name, size, url } = request.requestBody.file;
let photo = db.create('photo', { type, name, size, url });
return photo;
});
}
If you're using mirage locally, you can simulate different network conditions using a network
option on the upload
helper:
mirage/config.js
import { upload } from 'ember-file-upload/mirage';
export default function () {
this.post('/photos/new', upload(function (db, request) {
// snip snip snip...
}, { network: '3g' });
}
This allows you to handle different types of network conditions in your application easily by testing locally. In addition to the network
option, you can specify a timeout
that will cause the handler to respond with a HTTP 408 Request Timeout Error
.
The request object passed into the upload
function contains oodles of goodies that details what the file is. It provides the following fields out of the box:
name
- The filename.size
- The size of the file in bytes.type
- The MIME type of the file.extension
- The file extension.
For specific file types, we've done some work to make it easier to get more detailed information. A breakdown of this is below:
For audio files:
duration
- The duration of the audio, in seconds
For video files:
duration
- The duration of the video, in secondswidth
- The width of the video, in pixelsheight
- The height of the video, in pixels
For image files:
width
- The width of the image, in pixelsheight
- The height of the image, in pixels
For GIFs:
duration
- The duration of the GIF, if animatedanimated
- Whether the GIF is animated
And now, finally! Triggering a file upload:
import File from 'ember-file-upload/file';
import upload from '../helpers/upload';
module('/photos/create');
test('uploading a file', async function () {
await visit('/photos/new');
let gif = File.fromDataUrl('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
await upload('#add-photo', gif, 'pixel.gif');
let photo = server.db.photos[0];
assert.equal(photo.filename, 'pixel.gif');
});
2.0.0-beta.27
tldr; IE11 users now have support for dragging and dropping, and Ember Fastboot run apps won't break on startup.
Courtesy @ef4 for Fastboot support and @chrisdpeters for IE support 🎉
2.0.0-beta.26
tldr; You can prevent Content-Type
from being sent along with a request by setting contentType
to null
or undefined
.
2.0.0-beta.25
tldr; 🚀 Fastboot apps can now use ember-file-upload
.
2.0.0-beta.24
tldr; You can nest svg
elements in a file-upload
component.
✨ Now you can have pretty upload illustrations and icons for your uploads ✨