8000 Parse multi-part response · Issue #107 · wookay/Bukdu.jl · GitHub
[go: up one dir, main page]

Skip to content

Parse multi-part response #107

Closed
Closed

Description

@NiharikaPatel

I am sending a json and a binary or text file and I need to Parse the response.body to just get the contents of it. Right now the request body looks like this

-----------------------------211044896921589655921082427940
Content-Disposition: form-data; name="file"; filename="hw.txt"
Content-Type: text/plain

Hello World

-----------------------------211044896921589655921082427940
Content-Disposition: form-data; name="document"; filename="blob"
Content-Type: application/json

[object Object],[object Object],[object Object],[object Object]
-----------------------------211044896921589655921082427940--

How do i extract just the "Hello World" part without
-----------------------------211044896921589655921082427940
Content-Disposition: form-data; name="file"; filename="hw.txt"
Content-Type: text/plain

Activity

  1. wookay commented on Sep 15, 2020

    @wookay
    Owner

    related https://github.com/wookay/Bukdu.jl/blob/master/src/plugs/ContentParsers.jl

    using Bukdu.Plug.ContentParsers: FormScanner, scan
    
    reqbody = """
    -----------------------------211044896921589655921082427940
    Content-Disposition: form-data; name="file"; filename="hw.txt"
    Content-Type: text/plain
    
    Hello World
    
    -----------------------------211044896921589655921082427940
    Content-Disposition: form-data; name="document"; filename="blob"
    Content-Type: application/json
    
    [object Object],[object Object],[object Object],[object Object]
    -----------------------------211044896921589655921082427940--
    """
    
    scanner = FormScanner(Vector{UInt8}(reqbody), "-----------------------------211044896921589655921082427940")
    body_params = scan(scanner)
    @info :data String(read(body_params[1][2].data))
  2. NiharikaPatel commented on Sep 16, 2020

    @NiharikaPatel
    Author

    Great! thank you, however, the "-----------------------------211044896921589655921082427940" changes every time. Is there a generalized way of finding the separator before feeding it in the FormScanner ?

  3. wookay commented on Sep 16, 2020

    @wookay
    Owner
  4. NiharikaPatel commented on Sep 16, 2020

    @NiharikaPatel
    Author

    Thanks! The json part is still as [object, Object]

  5. NiharikaPatel commented on Sep 16, 2020

    @NiharikaPatel
    Author

    Figured it out, I was sending the json as an object instead of a string from the front end. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0