I'm trying to upload metadata with an object, but ...
# help
g
I'm trying to upload metadata with an object, but I'm having issues on the jvm side the python wrapper is the following
Copy code
obj = lakefs.WriteableObject(repository_id=repo.properties.id, reference_id="main", path=path, client=clt).upload(
        data=data, metadata=metadata)
which, in turn, shall call this
this is what I wrote so far
Copy code
val repo = setupRepo()
        val branch = "main"
        val file = tempFile.apply { writeText("test_data") }
        val path = "test_obj"
        val metadata = mapOf("foo" to "bar")
        val headers = mapOf("Accept" to "application/json",
                            "Content-Type" to "application/octet-stream") + metadata.mapKeys { (k, _) -> "$LAKEFS_METADATA_PREFIX$k" }
        val resourcePath = "/repositories/${repo.id}/branches/$branch/objects"
        val queryParams = URI(hashMapOf("path" to path).encode())
        testClient.updateParamsForAuth(arrayOf("basic_auth"), null, headers, null, resourcePath, "POST", queryParams)
        val stats = testClient.objectsApi.uploadObject(repo.properties!!.id, branch, path).content(file).execute()
        assert(stats.path == path)
        assert(stats.mtime <= System.currentTimeMillis())
        assert(stats.sizeBytes!! == file.length())
        println(stats.metadata)
        //        assert(stats.metadata == metadata)
        assert(stats.contentType == "application/octet-stream")
but
stats.metadata
is still empty..
headers
is
{Accept=application/json, Content-Type=application/octet-stream, x-lakefs-meta-foo=bar}
queryParams
is
?path=test_obj
the returning
stats
is
Copy code
class ObjectStats {
    path: test_obj
    pathType: object
    physicalAddress: local:///home/elect/lakefs/data/block/tmp/junit15669663127659863511/data/ghkntbipdakrls40rqlg/cnios1ipdakrls40rqr0
    physicalAddressExpiry: null
    checksum: 6af8307c2460f2d208ad254f04be4b0d
    sizeBytes: 9
    mtime: 1709542918
    metadata: {}
    contentType: application/octet-stream
    additionalProperties: null
}
what am I doing wrong?
n
Hi @Giuseppe Barbieri, Can you please provide the lakeFS version and SDK version you are using?
g
1.10.0 and
"io.lakefs:sdk:1.11.0"
the mismatch is the error? should they be aligned or?
n
It should be fine - which Python SDK version are you using?
g
I'm not using the Python SDK
I'm using the java one
n
Copy code
I'm trying to upload metadata with an object, but I'm having issues on the jvm side
the python wrapper is the following
What did you mean by that?
g
I'm following the python code, trying to replicate the same on the jvm side
n
That's not going to work for you. The Python wrapper has explicit code which makes this happen.
To make this work in the Java SDK - I suggest you use the Get/SetPhysicalAddress method
g
how is that related to the metadata, sorry?
The Python wrapper has explicit code which makes this happen.
isn't this one?
n
It is - but to imitate that you will probably have to build the post request by yourself, exactly as the Python wrapper does and not just call uploadObject. The simpler alternative is to use what I suggested
g
so, I shall use
Get/SetPhysicalAddress
methods to upload the metadata? How?
my problem is really just the metadata
all the rest work flawless
n
What's your underlying storage?
g
local
Copy code
val storageNamespace by lazy { "local:/$tempFolder" }
n
The UploadObject API does not support user metadata ATM. If you wish to pass metadata you can do: 1. The same as you did but build the POST request on your own passing the metadata in the header 2. Use the Staging API (Get/LinkPhysicalAddress)
g
ah,
user_metadata
, thanks
👍🏽 1