ripe-tech/ripe-sdk

createAttachmentOrder with meta

gcandal opened this issue · 8 comments

Rationale

The creation of order attachments expects a file and a meta dictionary (see https://github.com/ripe-tech/ripe-core/blob/ba23882efa65acb165e924c6f836c6933646604f/src/ripe_core/controllers/api/order.py#L97).

However, the current SDK implementation of the endpoint doesn't support meta (see

dataM: {
).

Description

The implementation of the rationale above could probably be similar to:

    options = Object.assign(options, {
        url: url,
        method: "POST",
        dataM: {
            file: file,
            meta: JSON.stringify(meta)
        },
        auth: true
    });

But unless I'm missing something obvious, ripe-sdk doesn't support strings as values when using a multipart payload dataM (see

ripe.Ripe.prototype._encodeMultipart = function(fields, mime = null, doseq = false) {
).

Trying to use them results in RangeError: offset is out of bounds because the string is not being encoded, resulting in this:

image

Related: https://github.com/ripe-tech/ripe-core/pull/4564

Woof, Woof!

Thank you for submitting the "createAttachmentOrder with meta" issue 😎.

Please do not forget to review our internal guidelines:

  • Describe the problem in the best possible way
  • Include at least the Description section, but considered adding other sections
  • Avoid suggesting immediate solutions, think deeply about the problem
  • Engage in the Triage process being as responsive as possible
  • Understand and accept the possibly large amount of execution time
  • Avoid immediate reallocation of the issue, let triage do their job

Engaging in the development process in the best possible way helps it being efficient and fast.

Your friend,
Tobias (Platforme's mascot)

Tobias Bot

The suggested implementation does not work... if working with multipart you cannot pass dictionaries

You mean dictionaries as values? I didn't, I used a string.

yes, but on the server-side you'll not be able to de-serialize them automatically, so no good to pass JSON.dumps

You need to use something like meta in the order POST... and still the multi-part issue with strings (in the SDK) would have to be fixed

ok maybe I'm wrong and now we support automatic JSON casting in Appier... Go ahead and try to see what's wrong with the multi-part encoding... But check the appier and yonius implementations as the multipart encoder should be aligned with both

Screenshot 2021-06-08 at 11 40 19

@gcandal let's also create some unit tests to avoid regression for this mixed types multipart situation