Socket
Socket
Sign inDemoInstall

ember-cli-form-data

Package Overview
Dependencies
291
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ember-cli-form-data

Ember-CLI addon that adds FormData file upload to the RESTAdapter


Version published
Weekly downloads
1.7K
decreased by-3.64%
Maintainers
1
Install size
29.5 MB
Created
Weekly downloads
 

Readme

Source

ember-cli-form-data

This Ember-CLI addon adds file uploads through FormData to the Ember Data

Install

ember install ember-cli-form-data

Usage

Add a file field on the model

// models/post.js

export default DS.Model.extend({
  attachment: DS.attr('file'),
  ...
});

Add the FormDataMixin to your post adapter. Run ember g adapter post if you don't have the adapter.

// adapters/post.js

import FormDataAdapterMixin from 'ember-cli-form-data/mixins/form-data-adapter';

export default ApplicationAdapter.extend(FormDataAdapterMixin, {
  // Adapter code
});

Then you can use an <input type='file' id='file-field'/> to send the attachment:

var file = document.getElementById('file-field').files[0];
model.set('attachment', file);
model.save();

This will send the attachment and all other attributes as a FormData object.

Flatten FormData fields

Some api's desire the form data fields to not include the root object name. For example, the default adapter behavior would result in post[title] in your serialized data. If your api instead expects just title, add disableRoot: true to remove the model name from the fields.

Other Resources

  • EmberScreencasts video on using ember-cli-form-data

Thanks

This addon was inspired by Matt Beedle's blog post http://blog.mattbeedle.name/posts/file-uploads-in-ember-data/

Keywords

FAQs

Last updated on 30 Nov 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc