knownasilya/ember-plupload

Issue with PLUPLOAD_BASE_URL

dant00ine opened this issue · 3 comments

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?

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?

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(...