<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="144425" data-post-id="144425">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="massimo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/massimo/120/5555_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  massimo
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<blockquote>
<p>At first I’d need some reliable source of such magic numbers and their mapping to MIME-types.</p>
</blockquote>
<p>it’s already on your computer</p>
<p><code>/usr/share/mime/magic</code> contains the compiled informations about magic numbers while <code>/usr/share/mime/globs</code> all the glob patterns.</p>
<p><code>file --mime-type</code> results are as reliable as the databases on your system is good.</p>
<p>The database is populated by the applications installing their own mime specifications or manually by creating the correct XML files and then running <code>update-mime-database</code>.</p>
<blockquote>
<p>but I don’t think that a sequential pattern match is fast enough.</p>
</blockquote>
<p>On my system magic is not that big</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">wc -l /usr/share/mime/magic 
1767 /usr/share/mime/magic
</code></pre>
<p>Half of the lines are taken by mime definitions, so in total it’s less than a thousand patterns.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">wc -l /etc/mime.types 
846 /etc/mime.types
</code></pre>
<p>Even testing all of them sequentally should be  fast enough.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="144425" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/mime-type-detection-by-magic-numbers/213/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-144425" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="144425"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #21"></div>
  </section>
</div>
    <div class="postbit" id="144559" data-post-id="144559">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="benonymus" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benonymus/120/31839_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  benonymus
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>figured it out,</p><aside class="quote" data-post="1" data-topic="25589">
  <div class="title">
    <div class="quote-controls"></div>
    <img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benonymus/48/31839_2.png" class="avatar">
    <div class="quote-title__text-content">
      <a href="https://forum.elixirforum.com/t/how-to-validate-files-uploaded-by-user-effectively/25589" rel="nofollow">How to validate files uploaded by user effectively?</a> <a class="badge-category__wrapper " href="/c/questions-help/questions/53" rel="nofollow"><span data-category-id="53" style="--category-badge-color: #C14BFB; --category-badge-text-color: #000000; --parent-category-badge-color: #C14BFB;" data-parent-category-id="171" data-drop-close="true" class="badge-category --style-square --has-parent" title="Elixir Questions / Help"><span class="badge-category__name">Questions</span></span></a>
    </div>
  </div>
  <blockquote>
    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: <a href="https://hex.pm/packages/file_info" class="inline-onebox-loading" rel="nofollow">https://hex.pm/packages/file_info</a> 
but it deosn’t want to work yet
  </blockquote>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="144559" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/mime-type-detection-by-magic-numbers/213/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-144559" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="144559"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #22"></div>
  </section>
</div>
    <div class="postbit" id="144566" data-post-id="144566">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="NobbZ" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/NobbZ/120/27235_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  NobbZ
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Could you please tell us your solution?</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://xkcd.com/979/">
  <header class="source">
      <img src="https://xkcd.com/s/919f27.ico" class="site-icon" alt="" width="32" height="32">

      <a href="https://xkcd.com/979/" target="_blank" rel="noopener nofollow">xkcd</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:485/270;"><img src="https://imgs.xkcd.com/comics/wisdom_of_the_ancients.png" class="thumbnail" alt="" width="485" height="270"></div>

<h3><a href="https://xkcd.com/979/" target="_blank" rel="noopener nofollow">Wisdom of the Ancients</a></h3>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="144566" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/mime-type-detection-by-magic-numbers/213/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-144566" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="144566"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #23"></div>
  </section>
</div>
    <div class="postbit" id="144570" data-post-id="144570">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="kokolegorille" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kokolegorille/120/4784_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  kokolegorille
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<pre data-code-wrap="elixir"><code class="lang-elixir">%Plug.Upload{
  content_type: "application/pdf",
  filename: "random-grid.pdf",
  path: "/tmp/plug-1569/multipart-1569289758-138513881763554-3"
}
</code></pre>
<p>The path includes the filename already… adding filename results in an error.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="144570" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/mime-type-detection-by-magic-numbers/213/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-144570" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="144570"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #24"></div>
  </section>
</div>
    <div class="postbit" id="144571" data-post-id="144571">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="benonymus" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benonymus/120/31839_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  benonymus
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>precisely, I was trying to use the filename from plug, you need to use the path</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="144571" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/mime-type-detection-by-magic-numbers/213/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-144571" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="144571"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #25"></div>
  </section>
</div>
    <div class="postbit" id="192699" data-post-id="192699">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="pinksynth" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pinksynth/120/22768_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  pinksynth
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Your wrapper is probably a much more sane solution than this, but just for fun I wrote an example of how this could be done in pure Elixir using the fun of pattern matching.</p>
<aside class="onebox githubgist" data-onebox-src="https://gist.github.com/pinksynth/0ba2660cd02d0af8854dbcc3d445069b">
  <header class="source">

      <a href="https://gist.github.com/pinksynth/0ba2660cd02d0af8854dbcc3d445069b" target="_blank" rel="noopener nofollow ugc">gist.github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://gist.github.com/pinksynth/0ba2660cd02d0af8854dbcc3d445069b" target="_blank" rel="noopener nofollow ugc">https://gist.github.com/pinksynth/0ba2660cd02d0af8854dbcc3d445069b</a></h4>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="192699" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/mime-type-detection-by-magic-numbers/213/27">Post #26</a>
	                </div>
	            </div>
              <div id="likers-container-192699" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="192699"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #26"></div>
  </section>
</div>
    <div class="postbit" id="251807" data-post-id="251807">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="michelson" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/michelson/120/3421_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  michelson
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi, I’ve just implemented this <a href="https://github.com/chaskiq/ex-marcel" class="inline-onebox" rel="noopener nofollow ugc">GitHub - chaskiq/ex-marcel: Find the mime type of files, examining file, filename and declared type · GitHub</a>, it’s a port from Rails Marcel gem, the library gives the mime type by looking at the magic bytes but also by name or extension as fallbacks.<br>
It’s just a pure elixir library, dependency-free.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="251807" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/mime-type-detection-by-magic-numbers/213/28">Post #27</a>
	                </div>
	            </div>
              <div id="likers-container-251807" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="251807"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>