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

Issue with PLUPLOAD_BASE_URL #69

Open
dant00ine opened this issue May 5, 2016 · 3 comments
Open

Issue with PLUPLOAD_BASE_URL #69

dant00ine opened this issue May 5, 2016 · 3 comments

Comments

@dant00ine
Copy link

I am trying to upload files to my express server, so I added this to my config/environment.js file:

ENV.PLUPLOAD_BASE_URL = "http://localhost:3200"

Problem is, it's still sending the requests to 4200 -- any idea where I might have gone wrong here?

@tim-evans
Copy link
Collaborator

I'd put a debugger here:

https://github.com/tim-evans/ember-plupload/blob/master/app/components/pl-uploader.js#L6

To see what happens :)

@dant00ine
Copy link
Author

Thanks Tim!
I'm seeing the correct URL in the debugger, quite vexing!

exports['default'] = _emberPluploadComponentsPlUploader['default'].extend({
    BASE_URL: BASE_URL     // BASE_URL = "http://localhost:3200/"
  });

The ember-plupload/config/environment.js file is empty for me, and debugger statements won't work there. I'm assuming the information from my environment.js file gets loaded in here, so that's probably not the problem?
Might it be something with my implementation of the component in my template or js code? I'm sticking to the example structures in your readme.

{{#pl-uploader name="phone-bill" for="upload-image" extensions="jpg jpeg png gif" onfileadd="uploadImage" as |queue dropzone| }}
            <div class="dropzone" id={{dropzone.id}}>
              {{#if dropzone.active}}
                {{#if dropzone.valid}}
                    Drop to upload
                {{else}}
                    Invalid
                {{/if}}
              {{else if queue.length}}
                  Uploading {{queue.length}} files. ({{queue.progress}}%)
              {{else}}
                  <h4>Upload Images</h4>
                  <p>
                    {{#if dropzone.enabled}}
                        Drag and drop images onto this area to upload them or
                    {{/if}}
                      <a id="upload-image">Add an Image.</a>
                  </p>
              {{/if}}
            </div>
        {{/pl-uploader}}
uploadImage: function (file) {
      let location = this.currentModel;
      console.log(`what happens when we log location?: ${location}`);
      let image = this.get('store').createRecord('upload', {
        location: location,
        filename: get(file, 'name'),
        filesize: get(file, 'size')
      });

      file.read().then(function (url) {
        if (get(image, 'url') == null) {
          set(image, 'url', url);
        }
      });

      file.upload('/uploads/license').then(function (response) {
        set(image, 'url', response.headers.Location);
        return image.save();
      }, function () {
        image.rollback();
      });
    },

Still seeing: POST http://localhost:4200/uploads/license 404 (Not Found)

Any idea where this problem may lie? Has anyone else had trouble with the base url?

@keichan34
Copy link

It looks like PLUPLOAD_BASE_URL is for assets paths (swf, etc), not for the upload. Just specify an absolute URI in the upload function call and it should work:

import config from '../config/environment';
...
file.upload(`${config.API_BASE_URL}/uploads/license`).then(...

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

3 participants