Hello,
It turns out I'm still having trouble with file replacement. Things are much easier with the help of the pyDataverse tool (thank you Stefan!) but I'm experience an issue both with pyDataverse and direct curl access to the API.
If I replace a single file everything seems to work fine. But if I want to replace multiple files, everything after the 1st file gets a "-1" appended to the filename. Is it possible that the API treats published dataverses and draft dataverses differently? It seems like after 1 curl command, a copy of the dataverse is created and now exists in draft mode. Subsequent curl calls access that version perhaps? And then things behave differently?
Here is a simple example showing the issue using
https://demo.dataverse.org/dataset.xhtml?persistentId=doi:10.70122/FK2/EIB6CG where I'm attempting to replace both "foo.txt" and "bar.txt"
export SERVER_URL=
https://demo.dataverse.org
export ID_foo=doi:10.70122/FK2/EIB6CG/OFMC8B
export ID_bar=doi:10.70122/FK2/EIB6CG/YCYSP7
export FILE_foo=/home/kdm/tmp/DV/two/foo.txt
export FILE_bar=/home/kdm/tmp/DV/two/bar.txt
curl -H "X-Dataverse-key:$API_TOKEN" -X POST -F "file=@${FILE_foo}" -F 'jsonData={"description":"Foo", "forceReplace":true, "directoryLabel":"."}' "$SERVER_URL/api/files/:persistentId/replace?persistentId=$ID_foo"
curl -H "X-Dataverse-key:$API_TOKEN" -X POST -F "file=@${FILE_bar}" -F 'jsonData={"description":"Bar", "forceReplace":true, "directoryLabel":"."}' "$SERVER_URL/api/files/:persistentId/replace?persistentId=$ID_bar"
The return from the first curl call shows "foo.txt" as the replacement filename:
{"status":"OK","data":{"files":[{"description":"Foo","label":"foo.txt","restricted":false,"version":1,"datasetVersionId":167418,"dataFile":{"id":1579547,"persistentId":"","pidURL":"","filename":"foo.txt","contentType":"text/plain","filesize":6,"description":"Foo","storageIdentifier":"file://1742194cca8-40f3489766ee","rootDataFileId":1579546,"previousDataFileId":1579546,"md5":"e19673b6e69c5f73192e4f78f6e771ab","checksum":{"type":"MD5","value":"e19673b6e69c5f73192e4f78f6e771ab"},"creationDate":"2020-08-24"}}]}}
The return from the second curl call shows "bar-1.txt" as the replacement filename:
{"status":"OK","data":{"files":[{"description":"Bar","label":"bar-1.txt","restricted":false,"version":1,"datasetVersionId":167418,"dataFile":{"id":1579548,"persistentId":"","pidURL":"","filename":"bar-1.txt","contentType":"text/plain","filesize":6,"description":"Bar","storageIdentifier":"file://1742194d927-2a91b6b40468","rootDataFileId":1579545,"previousDataFileId":1579545,"md5":"17f50f4b842bd98f58f2e11c0848c821","checksum":{"type":"MD5","value":"17f50f4b842bd98f58f2e11c0848c821"},"creationDate":"2020-08-24"}}]}}
Is there some API feature that I'm missing that will let me replace >1 file at a time while controlling the filenames?
Thanks,
-k.