benonymus

benonymus

Hey I am using arc to manage my file uploads, and I am using the file extension whitelist, as it is in the examples, but is that safe enough?
Is it possible to have different checking on file(images, other types of files as well like docx, zip, etc) uploads?
I found this: file_info | Hex
but it deosn’t want to work yet

Showing Posts 1 to 10

OvermindDL1

OvermindDL1

How is it not wanting to work yet? What error did you get?

benonymus

benonymus OP

Hey I am getting this for this file upload:

%Plug.Upload{
  content_type: "application/pdf",
  filename: "random-grid.pdf",
  path: "/tmp/plug-1569/multipart-1569287514-743406783659766-2"
}

and I am trying to do this:

FileInfo.get_info(attachment.filename) 

I also tried to append the filename at the end of the path given here but I am getting the same result

error:

** (MimetypeParser.Exception) illegal characters "`"
        (mimetype_parser) lib/mimetype_parser.ex:14: MimetypeParser.parse!/2
        (file_info) lib/file_info/mime.ex:25: FileInfo.Mime.parse!/1
        (file_info) lib/file_info.ex:39: FileInfo.to_tuple/1
        (elixir) lib/stream.ex:565: anonymous fn/4 in Stream.map/2
        (elixir) lib/enum.ex:3317: Enumerable.List.reduce/3
        (elixir) lib/stream.ex:1568: Enumerable.Stream.do_each/4
        (elixir) lib/enum.ex:3015: Enum.reverse/1
        (elixir) lib/enum.ex:2647: Enum.to_list/1
        (elixir) lib/map.ex:181: Map.new_from_enum/1

I am getting hte same result for every single file.
The setup is the following, I am using ubuntu, and the project is running in a docker container if I run the file command inside the container it works.
If i run the project in iex mode and try to call

FileInfo.get_info/1

if I call it with files inside that very folder that i am in it works, I can get results like

%{"mix.lock" => %FileInfo.Mime{arguments: %{}, subtype: "plain", type: "text"}}

but with other files, outside this folder I can only get that same error from earlier

kokolegorille

kokolegorille

This for sure will not work… How do You append the file and path?

benonymus

benonymus OP

FileInfo.get_info("#{attachment.path}#{attachment.filename}")
kokolegorille

kokolegorille

You miss a slash in between, as I thought… the path is not valid without.

benonymus

benonymus OP

still doesnt want to work:

%Plug.Upload{
  content_type: "application/pdf",
  filename: "random-grid.pdf",
  path: "/tmp/plug-1569/multipart-1569289758-138513881763554-3"
}
FileInfo.get_info("#{attachment.path}/#{attachment.filename}")

getting the same error, but it did miss the slash so thank you for that

benonymus

benonymus OP

If i do just the underlying command:

System.cmd("file", ["--mime-type" | ["#{attachment.path}/#{attachment.filename}"]])

then the result is this:

{“/tmp/plug-1569/multipart-1569290249-648297072043659-1/random-grid.pdf: cannot open `/tmp/plug-1569/multipart-1569290249-648297072043659-1/random-grid.pdf’ (Not a directory)\n”,
0}

kokolegorille

kokolegorille

It is working fine on my pc with a pdf file…

iex> FileInfo.get_info "/Users/koko/downloads/MarcAurelePensees.pdf"
%{
  "/Users/koko/downloads/MarcAurelePensees.pdf" => %FileInfo.Mime{
    arguments: %{},
    subtype: "pdf",
    type: "application"
  }
}

But your error seems to be a non existant file… You should check first if the file exists.

File.exists? ...
benonymus

benonymus OP

ok, that says it doesn’t exist, but then how can plug and arc give a path to it and upload it?

kokolegorille

kokolegorille

From docs…

Note: This file is temporary, and Plug will remove it from the directory as the request completes. If we need to do anything with this file, we need to do it before then.

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews