Code Monkey home page Code Monkey logo

multipart.cr's Introduction

This shard been merged into the crystal standard library. Please use HTTP::FormData and HTTP::Multipart.

crystal-docs.org

multipart.cr

Shard which adds multipart support to crystal's stdlib.

Installation

Add this to your application's shard.yml:

dependencies:
  multipart:
    github: RX14/multipart.cr

Usage

require "multipart"

# Use HTTP::Multipart and HTTP::FormData

See the docs for code examples.

Development

TODO: Write development instructions here

Contributing

  1. Fork it ( https://github.com/RX14/multipart.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • RX14 - creator, maintainer

multipart.cr's People

Contributors

rx14 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

sdogruyol

multipart.cr's Issues

Crystal 0.20.3 Error

This works in Crystal 0.20.1 and 0.17.3

require "kemal"

post "/upload" do |env|
  parse_multipart(env) do |f|
    file_path = File.join Dir.current, "image.png"
    File.open(file_path, "w") do |file|
      IO.copy(f.data, file)
    end
    "Upload complete"
  end
end

Kemal.run

Error

Exception: header content contains invalid character '\u{0}' (ArgumentError)
0x10a0936c2: *CallStack::unwind:Array(Pointer(Void)) at ??
0x10a093661: *CallStack#initialize:Array(Pointer(Void)) at ??
0x10a093638: *CallStack::new:CallStack at ??
0x10a090651: *raise<Exception+>:NoReturn at ??
0x10a09048d: ~procProc(HTTP::Server::Context, Nil)@src/app.cr:3 at ??
0x10a08f4db: ~procProc(HTTP::Server::Context, String)@lib/kemal/src/kemal/route.cr:11 at ??
0x10a15195b: *Kemal::RouteHandler#process_request<HTTP::Server::Context>:HTTP::Server::Context at ??
0x10a1518d9: *Kemal::RouteHandler#call<HTTP::Server::Context>:HTTP::Server::Context at ??
0x10a1666d8: *Kemal::StaticFileHandler@HTTP::Handler#call_next<HTTP::Server::Context>:(Array(IO) | Bool | HTTP::Server::Context | HTTP::Server::Response | HTTP::Server::Response::Output | IO::FileDescriptor+ | Int32 | Nil) at ??
0x10a1655fd: *Kemal::StaticFileHandler#call<HTTP::Server::Context>:(Array(IO) | Bool | HTTP::Server::Context | HTTP::Server::Response | HTTP::Server::Response::Output | IO::FileDescriptor+ | Int32 | Nil) at ??
0x10a164c4f: *Kemal::CommonExceptionHandler@HTTP::Handler#call_next<HTTP::Server::Context>:(Array(IO) | Bool | HTTP::Server::Context | HTTP::Server::Response | HTTP::Server::Response::Output | IO::FileDescriptor+ | Int32 | Nil) at ??
0x10a164790: *Kemal::CommonExceptionHandler#call<HTTP::Server::Context>:(Array(IO) | Bool | HTTP::Server::Context | HTTP::Server::Response | HTTP::Server::Response::Output | IO::FileDescriptor+ | Int32 | Nil) at ??
0x10a163d76: *Kemal::CommonLogHandler@HTTP::Handler#call_next<HTTP::Server::Context>:(Array(IO) | Bool | HTTP::Server::Context | HTTP::Server::Response | HTTP::Server::Response::Output | IO::FileDescriptor+ | Int32 | Nil) at ??
0x10a16188d: *Kemal::CommonLogHandler#call<HTTP::Server::Context>:HTTP::Server::Context at ??
0x10a15134e: *Kemal::InitHandler@HTTP::Handler#call_next<HTTP::Server::Context>:(Array(IO) | Bool | HTTP::Server::Context | HTTP::Server::Response | HTTP::Server::Response::Output | IO::FileDescriptor+ | Int32 | Nil) at ??
0x10a150f9a: *Kemal::InitHandler#call<HTTP::Server::Context>:(Array(IO) | Bool | HTTP::Server::Context | HTTP::Server::Response | HTTP::Server::Response::Output | IO::FileDescriptor+ | Int32 | Nil) at ??
0x10a16cd09: *HTTP::Server::RequestProcessor#process<(OpenSSL::SSL::Socket::Server | TCPSocket+), (OpenSSL::SSL::Socket::Server | TCPSocket+), IO::FileDescriptor>:Nil at ??
0x10a16c705: *HTTP::Server::RequestProcessor#process<(OpenSSL::SSL::Socket::Server | TCPSocket+), (OpenSSL::SSL::Socket::Server | TCPSocket+)>:Nil at ??
0x10a167476: *HTTP::Server#handle_client<(TCPSocket+ | Nil)>:Nil at ??
0x10a0917c6: ~procProc(Nil)@/usr/local/Cellar/crystal-lang/0.20.3/src/http/server.cr:148 at ??
0x10a09d654: *Fiber#run:(IO::FileDescriptor | Nil) at ??
0x10a08ce99: ~proc2Proc(Fiber, (IO::FileDescriptor | Nil))@/usr/local/Cellar/crystal-lang/0.20.3/src/fiber.cr:29 at ??

To run

 curl -F "image1=@/Users/serdar/Desktop/Screenshots/logo.png" http://localhost:3000/upload

Downloading large file (700 Mo)

Hello !

I'm using the last Kemal version, which use your multipart lib.
Seems like a problem.

My code was something like

require "kemal"
Kemal.run

It may result as a segfault (caused by a IO -> String ?) if the file is too big.

GC Warning: Repeated allocation of very large block (appr. size 268439552):
    May lead to memory leak and poor performance
GC Warning: Failed to expand heap by 1076621312 bytes
GC Warning: Failed to expand heap by 1073745920 bytes
GC Warning: Out of Memory! Heap size: 1049 MiB. Returning NULL!
GC Warning: Failed to expand heap by 572706816 bytes
GC Warning: Failed to expand heap by 570650624 bytes
GC Warning: Out of Memory! Heap size: 1049 MiB. Returning NULL!
Invalid memory access (signal 11) at address 0x4
[4777829] *CallStack::print_backtrace:Int32 +117
[4701048] __crystal_sigfault_handler +56
[139970919276672] ???
[4785866] *String::Builder#to_s:String +154
[5094121] *HTTP::FixedLengthContent +249
[5568427] *HTTP::Request::from_io<(OpenSSL::SSL::Socket::Server | TCPSocket+)>:(HTTP::Request | HTTP::Request::BadRequest | Nil) +2251
[5652644] *HTTP::Server::RequestProcessor#process<(OpenSSL::SSL::Socket::Server | TCPSocket+), (OpenSSL::SSL::Socket::Server | TCPSocket+), IO::FileDescriptor>:Nil +132
[5652505] *HTTP::Server::RequestProcessor#process<(OpenSSL::SSL::Socket::Server | TCPSocket+), (OpenSSL::SSL::Socket::Server | TCPSocket+)>:Nil +57
[5652192] *HTTP::Server#handle_client<(TCPSocket+ | Nil)>:Nil +128
[4727443] ~procProc(Nil) +19
[4771166] *Fiber#run:(IO::FileDescriptor | Nil) +174
[4699878] ~proc2Proc(Fiber, (IO::FileDescriptor | Nil)) +6
[0] ???

Thank you for your work anyway ;) I'm following the PR on crystal-lang

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.