mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Merge pull request #3560 from simpl1g/fix_synchronous_api_uploads
FIX: Unable to create upload with :url in api
This commit is contained in:
commit
1b594027fb
2 changed files with 18 additions and 2 deletions
|
@ -4,7 +4,7 @@ class UploadsController < ApplicationController
|
|||
|
||||
def create
|
||||
type = params.require(:type)
|
||||
file = params[:file] || params[:files].first
|
||||
file = params[:file] || params[:files].try(:first)
|
||||
url = params[:url]
|
||||
client_id = params[:client_id]
|
||||
synchronous = is_api? && params[:synchronous]
|
||||
|
@ -52,7 +52,7 @@ class UploadsController < ApplicationController
|
|||
# API can provide a URL
|
||||
if file.nil? && url.present? && is_api?
|
||||
tempfile = FileHelper.download(url, SiteSetting.max_image_size_kb.kilobytes, "discourse-upload-#{type}") rescue nil
|
||||
filename = File.basename(URI.parse(file).path)
|
||||
filename = File.basename(URI.parse(url).path)
|
||||
else
|
||||
tempfile = file.tempfile
|
||||
filename = file.original_filename
|
||||
|
|
|
@ -53,6 +53,22 @@ describe UploadsController do
|
|||
expect(message.data).to be
|
||||
end
|
||||
|
||||
it 'is successful with synchronous api' do
|
||||
SiteSetting.stubs(:authorized_extensions).returns("*")
|
||||
controller.stubs(:is_api?).returns(true)
|
||||
|
||||
Jobs.expects(:enqueue).with(:create_thumbnails, anything)
|
||||
|
||||
FakeWeb.register_uri(:get, "http://example.com/image.png", :body => File.read('spec/fixtures/images/logo.png'))
|
||||
|
||||
xhr :post, :create, url: 'http://example.com/image.png', type: "avatar", synchronous: true
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
|
||||
expect(response.status).to eq 200
|
||||
expect(json["id"]).to be
|
||||
end
|
||||
|
||||
it 'correctly sets retain_hours for admins' do
|
||||
Jobs.expects(:enqueue).with(:create_thumbnails, anything)
|
||||
|
||||
|
|
Loading…
Reference in a new issue