Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/cloudex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ defmodule Cloudex do

defp sanitize_list([item | tail], sanitized_list) do
result =
if Regex.match?(~r/^(http|s3)/, item), do: {:ok, item}, else: handle_file_or_directory(item)
if Regex.match?(~r/^(http|s3)|(base64)/, item) do
{:ok, item}
else
handle_file_or_directory(item)
end

new_list = [result | sanitized_list]
sanitize_list(tail, new_list)
Expand Down
8 changes: 5 additions & 3 deletions lib/cloudex/cloudinary_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ defmodule Cloudex.CloudinaryApi do
end

@spec upload_file(String.t(), map) :: {:ok, %Cloudex.UploadedImage{}} | {:error, any}
defp upload_file(file_path, opts) do
defp upload_file(file, opts) do
options =
opts
|> extract_cloudinary_opts
Expand All @@ -93,9 +93,11 @@ defmodule Cloudex.CloudinaryApi do
|> unify
|> Map.to_list()

body = {:multipart, [{:file, file_path} | options]}
body_type = if Regex.match?(~r/base64/, file), do: :form, else: :multipart

post(body, file_path, opts)
body = {body_type, [{:file, file} | options]}

post(body, file, opts)
end

@spec extract_cloudinary_opts(map) :: map
Expand Down