Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 Delete #84

Open
variousred opened this issue Aug 27, 2015 · 7 comments
Open

S3 Delete #84

variousred opened this issue Aug 27, 2015 · 7 comments

Comments

@variousred
Copy link

This library used to have an asset delete function for s3 didnt it? How can that be accomplished now?

@variousred
Copy link
Author

This is what i'm doing now (coffeescript)

      uploader = EmberUploader.S3Uploader.create
        url: 'http://localhost:3000/api/v1/sign_delete?locationName=' + website.get('name')
        deleteAsset: (asset) ->
          self = this
          @signDelete(asset).then (json) ->
            url = asset.get('url')
            type = 'DELETE'
            self.authorizationAjax url, 'DELETE', json
        signDelete: (file) ->
          settings = 
            url: @get('url')
            type: 'GET'
            contentType: 'json'
            data: name: file.get('url').split('/').pop()
          @_ajax settings
        authorizationAjax: (url, method, signatureJson) ->
          self = this
          settings = 
            signature: signatureJson['signature']
            url: url
            type: method or 'POST'
            contentType: false
            processData: false
            headers:
              'Authorization': 'AWS4-HMAC-SHA256 Credential=' + signatureJson['aws_access_key_id'] + '/' + signatureJson['simple_date'] + '/' + signatureJson['region'] + '/s3/aws4_request, SignedHeaders=host;x-amz-date, Signature=' + signatureJson['signature']
              'x-amz-date': signatureJson['iso8601_date']
              'x-amz-content-sha256': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
          @_ajax settings
      uploader.deleteAsset(asset).then ((response) ->
        website.get('assets').removeObject(asset)
        asset.deleteRecord()
        asset.save()

@digitaltoad
Copy link
Member

I don’t think I’ve ever had a delete function for it.


Josh

On Thu, Aug 27, 2015 at 4:25 PM, Michael Mitchell
[email protected] wrote:

This is what i'm doing now

        deleteAsset: (asset) ->
          self = this
          @signDelete(asset).then (json) ->
            url = asset.get('url')
            type = 'DELETE'
            self.authorizationAjax url, 'DELETE', json
        signDelete: (file) ->
          settings = 
            url: @get('url')
            type: 'GET'
            contentType: 'json'
            data: name: file.get('url').split('/').pop()
          @_ajax settings
        authorizationAjax: (url, method, signatureJson) ->
          self = this
          settings = 
            signature: signatureJson['signature']
            url: url
            type: method or 'POST'
            contentType: false
            processData: false
            headers:
              'Authorization': 'AWS4-HMAC-SHA256 Credential=' + signatureJson['aws_access_key_id'] + '/' + signatureJson['simple_date'] + '/' + signatureJson['region'] + '/s3/aws4_request, SignedHeaders=host;x-amz-date, Signature=' + signatureJson['signature']
              'x-amz-date': signatureJson['iso8601_date']
              'x-amz-content-sha256': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
          @_ajax settings

Reply to this email directly or view it on GitHub:
#84 (comment)

@ValentinTrinque
Copy link

Any update for this issue ?

@digitaltoad
Copy link
Member

I haven't had time to look into this.

@ValentinTrinque
Copy link

Do you have any idea how you want to implement it ? I would be interested in participating.

@peavers
Copy link

peavers commented Nov 3, 2017

@ValentinTrinque this could be as simple as something like this

/**
* Deletes an S3 Asset
* @param asset
*/
deleteAsset(asset) {
    // You'll need to sign this somewhere, or have open permissions on your bucket - not recommended
    const url = `https://${asset.get('bucket')}.s3.amazonaws.com/${asset.get('key')}`;

    return this.get('ajax').delete(url).then(() => {
    asset.destroyRecord();
  });
},

Assumes your asset is the response from uploading, something like

import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  location: DS.attr('string'),
  bucket: DS.attr('string'),
  key: DS.attr('string'),
  eTag: DS.attr('string'),
});

@ValentinTrinque
Copy link

@peavers I am not working on the project with requiring this. However, thank you for the tip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants