我使用此代码从 init 中的数据库上传图像。现在我想在上传新图像时删除这个初始图像。
var o = $("div#uploader").dropzone({
url: "../../Merchant/UploadLogo",
paramName: "logo",
maxFiles: 1,
//enqueueForUpload: false,
maxfilesexceeded: function (file) {
this.removeAllFiles();
this.addFile(file);
},
addRemoveLinks: true,
uploadMultiple: false,
dictRemoveFile: "???",
removedfile: function(file) {
RemoveFile("Logo");
var _ref;
return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
},
init: function() {
var mockFile = { name: "avatar1.jpg", size: 12345, type: 'image/jpeg', url: "../../Merchant/GetLogo" };
this.options.addedfile.call(this, mockFile);
this.options.thumbnail.call(this, mockFile, mockFile.url);//uploadsfolder is the folder where you have all those uploaded files
}
});
Run Code Online (Sandbox Code Playgroud) 我正在努力Enum.map.当我向列表的所有元素添加100时,我发现了这个奇怪的输出.
为什么这样输出?事实证明,当我添加100时我得到一个字符串但是当我做其他操作时工作得很好.我摆弄了一些,我仍然得到了这样的意外结果.
我有一个rails应用程序,为注册用户提供大型静态文件.我可以按照这里的优秀指南来实现它:使用nginx,Rails 3.0和#send_file进行受保护的下载.下载和其他一切工作都很好,但只有这个问题 - Content-Length标题没有被发送.

对于小文件是可以的,但是当下载大文件时它会非常令人沮丧,因为下载管理器和浏览器没有显示任何进展.我怎样才能解决这个问题?我是否必须在nginx配置中添加一些内容,或者是否必须将其他选项传递给send_file我的rails控制器中的方法?我一直在网上搜索相当一段时间,但都没有成功.请帮忙!谢谢!
这是我的nginx.conf:
upstream unicorn {
server unix:/tmp/unicorn.awesomeapp.sock fail_timeout=0;
}
server {
listen 80 default_server deferred;
# server_name example.com;
root /home/deploy/apps/awesomeapp/current/public;
location ~ /downloads/(.*) {
internal;
alias /home/deploy/uploads/$1;
}
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Sendfile-Type X-Accel-Redirect;
proxy_set_header X-Accel-Mapping /downloads/=/home/deploy/uploads/;
proxy_pass http://unicorn;
}
error_page 500 502 …Run Code Online (Sandbox Code Playgroud) 我有一个Elixir由压缩字节组成的二进制字符串,我想将其压缩并从中提取“真实数据”:
iex(93)> data
<<31, 139, 8, 0, 0, 0, 0, 0, 0, 0, 109, 80, 203, 110, 218, 64, 0, 76, 171, 70, 141, 68, 78, 105, 213, 67, 171, 74, 168, 7, 212, 86, 50, 172, 189, 94, 236, 69, 66, 173, 49, 40, 56, 96, 76, 130, 31, 196, 23, 226, 216, 11, 44, 216, 94, 227, 117, 13, 238, 199, 244, 208, 207, 234, 23, 244, 23, 122, 43, 137, 218, 91, 110, 243, 208, …Run Code Online (Sandbox Code Playgroud) 我每次都拨打一些插头.我想创建一个单独的插件,为我调用所有这些.我该怎么做呢?
这是我目前试图做的事情:
defmodule MyApp.SpecialPlug do
import Plug.Conn
def init(default), do: default
def call(conn, default) do
plug SimplePlug1
plug SimplePlug2, args: :something
end
end
Run Code Online (Sandbox Code Playgroud)
但它抛出一个CompileError,说:undefined function plug
我正在写一个Elixir包,我想指定一个默认的应用程序配置(用户可以通过在其中指定自定义值来覆盖config.exs).我原本把它们放在我的项目中,config.exs直到我意识到不会为依赖于这个库的项目加载配置文件.
配置文件本身告诉您:
此配置在任何依赖项之前加载,并且仅限于此项目.如果另一个项目依赖于此项目,则不会加载此文件也不会影响父项目.因此,如果要为第三方用户提供应用程序的默认值,则应在"mix.exs"文件中完成.
我一直在努力了解如何在我的指定应用程序默认值mix.exs并使用它们.我目前的解决方案是使用Application.get_env/3默认参数,但这对我来说似乎不对,因为应用程序默认值会分散在代码中.
Application.get_env(:my_library, :arg, "default value")
Run Code Online (Sandbox Code Playgroud)
那么,我如何指定应用程序默认值mix.exs?
我有一个启动应用程序的依赖项,但我只想使用其模块并且不希望其主管运行。如何将其从启动中排除?
Mix.Project我在 app.start、run 或模块中没有找到与此相关的任何内容
我正在阅读 Phoenix 1.4 书,当我尝试通过终端将数据输入数据库时,我进入“使用存储库数据”部分,但出现错误。
\n\n我的 IEx 会话:
\n\niex(1)> alias Rumbl.Repo\nRumbl.Repo\niex(2)> alias Rumbl.Accounts.User\nRumbl.Accounts.User\niex(3)> Repo.insert(%User{\n...(3)> name: "Jos\xc3\xa9", username: "josevalim"\n...(3)> })\n[debug] QUERY ERROR db=16.7ms queue=1.2ms\nINSERT INTO "users" ("name","username","inserted_at","updated_at") VALUES ($1,$2,$3,$4) RETURNING "id" ["Jos\xc3\xa9", "josevalim", ~N[2018-11-24 11:47:30], ~N[2018-11-24 11:47:30]]\nRun Code Online (Sandbox Code Playgroud)\n\n它引发了以下错误:
\n\n** (Ecto.ConstraintError) constraint error when attempting to insert struct:\n\n * users_username_index (unique_constraint)\n\nIf you would like to stop this constraint violation from raising an\nexception and instead add it as an error to your changeset, please\ncall `unique_constraint/3` on your changeset with the …Run Code Online (Sandbox Code Playgroud) I know we can get the full stacktrace using __STACKTRACE__ in a catch/rescue block in elixir, but what's the correct way of printing it? In my case, I rescue from an error but I still want to log it to console. This is what I'm doing right now:
def unreliable_method(item) do
# Do something with `item`
:ok
rescue
_err ->
Logger.error("Failed for item: #{inspect(item)}")
Logger.error(inspect(__STACKTRACE__))
{:error, :processing_failed}
end
Run Code Online (Sandbox Code Playgroud) Elixir中是否有以下功能:
目前,我已经编写了这样的函数,尽管为每个我要写入其父母可能还不存在的文件编写的项目都非常麻烦。
defp write_to_file(path, contents) do
with :ok <- File.mkdir_p(Path.dirname(path)),
:ok <- File.write(path, contents)
do
:ok
end
end
Run Code Online (Sandbox Code Playgroud)
最理想的情况是这样的东西作为Elixir标准库的一部分存在,但是我找不到这样的东西
File.write(path, content, create_parents: true)
Run Code Online (Sandbox Code Playgroud) elixir ×8
compression ×1
dropzone.js ×1
ecto ×1
elixir-mix ×1
file-io ×1
http-headers ×1
javascript ×1
jquery ×1
nginx ×1
rescue ×1
stack-trace ×1
zip ×1