STOW-RS POST method using curl command

947 views
Skip to first unread message

Deeps

unread,
Jun 6, 2020, 12:00:57 PM6/6/20
to dcm4che
Hi,
     I am trying to store a dicom image using STOW-RS POST method. But I am not able to successfully execute the command.

curl -F file=@"/file-path/1.dcm" -H "Accept: application/json" -H "Content-type: application/json" -H "Authorization: Bearer $TOKEN" -X POST "http://<IP>:8080/dcm4chee-arc/aets/DCM4CHEE/rs/studies"

Please help me with this command and also how this image will be saved in dcm4chee-arc-light? Will this create a new study and save this as instance? What changes do I need to follow if I am trying to send a pdf or video file?

Vrinda Nayak

unread,
Jun 6, 2020, 12:17:29 PM6/6/20
to dcm4che
To store objects to archive using curl, you need to first wrap the files as part of Multipart related MIME message. Also ensure to use the correct Content type header while storing the objects. For reference see https://github.com/dcm4che/dcm4chee-arc-light/wiki/Store-objects-by-STOW-RS#using-curl

You can send pdf and videos similar to the example given for jpeg images in the same link. Just ensure to use the correct Content type while creating the MIME, according to pdf or videos files respectively.

Deeps

unread,
Jun 6, 2020, 2:20:52 PM6/6/20
to dcm4che

Thank you Vrinda. I successfully stored 1 dicom file.

Deeps

unread,
Jun 8, 2020, 11:30:12 AM6/8/20
to dcm4che

Hi Vrinda,
            I was able to store a dicom image as well as a jpeg image using the method you told. And I tried the same method to store a pdf file using the metadata.json, but that didnt work.

echo -ne "\r\n--myboundary\r\nContent-Type: application/dicom+json\r\n\r\n" > mime.metadata.head
echo -ne "\r\n--myboundary\r\nContent-Type: application/pdf\r\nContent-Location: /home/Downloads/image.pdf\r\n\r\n" > mime.pdf1.head
echo -ne "\r\n--myboundary--" > mime.tail
cat mime.metadata.head /home/Downloads/metadata.json mime.pdf1.head /home/Downloads/image.pdf mime.tail > metadata+pdf.mime

curl -X POST -H "Content-Type: multipart/related; type=\"application/dicom+json\"; boundary=myboundary" \
     http://IP:8080/dcm4chee-arc/aets/DCM4CHEE/rs/studies --data-binary @metadata+pdf.mime -H "Authorization: Bearer $TOKEN";

On executing this, I am getting:

<?xml version="1.0" encoding="UTF-8"?><NativeDicomModel xml:space="preserve"><DicomAttribute keyword="ErrorComment" tag="00000902" vr="LO"><Value number="1">Missing SamplesPerPixel (0028,0002)</Value></DicomAttribute><DicomAttribute keyword="RetrieveURL" tag="00081190" vr="UR"/><DicomAttribute keyword="FailedSOPSequence" tag="00081198" vr="SQ"><Item number="1"><DicomAttribute keyword="ReferencedSOPClassUID" tag="00081150" vr="UI"><Value number="1">1.2.840.10008.5.1.4.1.1.7</Value></DicomAttribute><DicomAttribute keyword="ReferencedSOPInstanceUID" tag="00081155" vr="UI"><Value number="1">2.25.1208443086719494618649377806679358536545678</Value></DicomAttribute><DicomAttribute keyword="FailureReason" tag="00081197" vr="US"><Value number="1">43264</Value></DicomAttribute></Item></DicomAttribute></NativeDicomModel>

Do I need to include more attribute values in metadata.json?







On Saturday, June 6, 2020 at 9:30:57 PM UTC+5:30, Deeps wrote:

Vrinda Nayak

unread,
Jun 8, 2020, 2:03:43 PM6/8/20
to dcm4che
It seems you are reusing the metadata of your image file for pdf. The metadata should not contain PixelData attribute but instead shall contain EncapsulatedDocument attribute for pdf. The metadata.json example given in the wiki was for a jpeg image. You need to adjust your metadata to align it with pdf files. For reference, see the contents of metadata xml/json using stowrs tool to store pdf file to archive from dcm4che library toolkit.
https://github.com/dcm4che/dcm4che/blob/master/dcm4che-tool/dcm4che-tool-stowrs/README.md
https://github.com/dcm4che/dcm4che/blob/master/dcm4che-assembly/src/etc/stowrs/encapsulatedPDFMetadata.xml

Pela Silveira

unread,
Oct 7, 2020, 8:06:21 PM10/7/20
to dcm4che
Hello

I am trying to store a PDF with curl, I tryed  using metadata informed above, but I couldnt encapsulate object as desired.

Here are my tests:
meta.json:
**************
[
    {
        "00080005": {
            "vr": "CS",
            "Value": [
                "ISO_IR 192"
            ]
        },
        "00080012": {
            "vr": "DA",
            "Value": [
                "20201007"
            ]
        },
        "00080013": {
            "vr": "TM",
            "Value": [
                "150005.590"
            ]
        },
        "00080016": {
            "vr": "UI",
            "Value": [
                "1.2.840.10008.5.1.4.1.1.104.1"
            ]
        },
        "00080018": {
            "vr": "UI",
            "Value": [
                "2.25.166747785617362983879345208032852350971111111"
            ]
        },
        "00080020": {
            "vr": "DA",
            "Value": [
                "20201007"
            ]
        },
        "00080030": {
            "vr": "TM"
        },
        "00080050": {
            "vr": "SH"
        },
        "00080060": {
            "vr": "CS",
            "Value": [
                "DOC"
            ]
        },
        "00080064": {
            "vr": "CS",
            "Value": [
                "SD"
            ]
        },
        "00080090": {
            "vr": "PN"
        },
        "0008103E": {
            "vr": "LO",
            "Value": [
                "Imported PDF"
            ]
        },
        "00100010": {
            "vr": "PN",
            "Value": [
                {
                    "Alphabetic": "RAMA"
                }
            ]
        },
        "00100020": {
            "vr": "LO",
            "Value": [
                "11111111112"
            ]
        },
        "0020000D": {
            "vr": "UI",
            "Value": [
                "2.25.1025127776690586277031657255028773535201122222222"
            ]
        },
        "0020000E": {
            "vr": "UI",
            "Value": [
                "2.25.675377690722349966892631201265521004413331333333333"
            ]
        },
        "00200010": {
            "vr": "SH"
        },
        "00200011": {
            "vr": "IS",
            "Value": [
                1
            ]
        },
        "00200013": {
            "vr": "IS",
            "Value": [
                1
            ]
        },
        "00280301": {
            "vr": "CS",
            "Value": [
                "YES"
            ]
        },
        "00420010": {
            "vr": "ST",
            "Value": [
                "Informe Imagenes"
            ]
        },
        "00420012": {
            "vr": "LO",
            "Value": [
                "application/pdf"
            ]
        }
    }
]
*************************

script.sh:

TOKEN=$(curl -X POST $AUTHHOST -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -d "grant_type=client_credentials&client_id=xx&client_secret=x-x-x-80e9-73bdc7730c83" | python -c "import sys, json; print json.load(sys.stdin)['access_token']")


echo -ne "\r\n--myboundary\r\nContent-Type: application/pdf\r\nContent-Location: my_pdf.pdf\r\n\r\n" > mime.pdf1.head
echo -ne "\r\n--myboundary\r\nContent-Type: application/dicom+json\r\n\r\n" > mime.metadata.head
echo -ne "\r\n--myboundary--" > mime.tail

cat mime.metadata.head meta2.json mime.pdf1.head my_pdf.pdf  mime.tail > metadata+pdf.mime

curl -X POST -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: multipart/related; type=\"application/dicom+json\"; boundary=myboundary" "${PACS}" --data-binary @metadata+pdf.mime


*******************************************************
psilveira@xxx:~/pdf2dcm$ curl   -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json; type=\"application/dicom+json\"" "${PACS}${STUDY}"
--a47cc46f-5fdf-474a-9891-4c18c68668e7
Content-ID: <14a01bd5-19e4-4922-a175-19c21a7abe5e@resteasy-multipart>
Content-Type: application/dicom

DICMUL�OBUI1.2.840.10008.5.1.4.1.1.104.1UI22.25.166747785617362983879345208032852350971111111UI1.2.840.10008.1.2.1UI1.2.40.0.13.1.3SHdcm4che-5.22.CS
ISO_IR 19D2020100TM
150005.59UI1.2.840.10008.5.1.4.1.1.104.UI22.25.16674778561736298387934520803285235097111111 D20201000TPS`CSDOCdCSS�P>LO
                      Imported PDFPNRAMA LO
                                           111111UI62.25.1025127776690586277031657255028773535201122222222 UI82.25.675377690722349966892631201265521004413331333333333 SH IS1  IS1 (CSYES BSTInforme ImagenesBLOapplication/pdf 

********************************************************

psilveira@xxxx:~/pdf2dcm$ dcmdump 2.25.166747785617362983879345208032852350971111111.dcm 

# Dicom-File-Format

# Dicom-Meta-Information-Header
# Used TransferSyntax: Little Endian Explicit
(0002,0000) UL 184                                      #   4, 1 FileMetaInformationGroupLength
(0002,0001) OB 00\01                                    #   2, 1 FileMetaInformationVersion
(0002,0002) UI =EncapsulatedPDFStorage                  #  30, 1 MediaStorageSOPClassUID
(0002,0003) UI [2.25.166747785617362983879345208032852350971111111] #  50, 1 MediaStorageSOPInstanceUID
(0002,0010) UI =LittleEndianExplicit                    #  20, 1 TransferSyntaxUID
(0002,0012) UI [1.2.40.0.13.1.3]                        #  16, 1 ImplementationClassUID
(0002,0013) SH [dcm4che-5.22.4]                         #  14, 1 ImplementationVersionName

# Dicom-Data-Set
# Used TransferSyntax: Little Endian Explicit
(0008,0005) CS [ISO_IR 192]                             #  10, 1 SpecificCharacterSet
(0008,0012) DA [20201007]                               #   8, 1 InstanceCreationDate
(0008,0013) TM [150005.590]                             #  10, 1 InstanceCreationTime
(0008,0016) UI =EncapsulatedPDFStorage                  #  30, 1 SOPClassUID
(0008,0018) UI [2.25.166747785617362983879345208032852350971111111] #  50, 1 SOPInstanceUID
(0008,0020) DA [20201007]                               #   8, 1 StudyDate
(0008,0030) TM (no value available)                     #   0, 0 StudyTime
(0008,0050) SH (no value available)                     #   0, 0 AccessionNumber
(0008,0060) CS [DOC]                                    #   4, 1 Modality
(0008,0064) CS [SD]                                     #   2, 1 ConversionType
(0008,0090) PN (no value available)                     #   0, 0 ReferringPhysicianName
(0008,103e) LO [Imported PDF]                           #  12, 1 SeriesDescription
(0010,0010) PN [RAMA]                                   #   4, 1 PatientName
(0010,0020) LO [11111111112]                            #  12, 1 PatientID
(0020,000d) UI [2.25.1025127776690586277031657255028773535201122222222] #  54, 1 StudyInstanceUID
(0020,000e) UI [2.25.675377690722349966892631201265521004413331333333333] #  56, 1 SeriesInstanceUID
(0020,0010) SH (no value available)                     #   0, 0 StudyID
(0020,0011) IS [1]                                      #   2, 1 SeriesNumber
(0020,0013) IS [1]                                      #   2, 1 InstanceNumber
(0028,0301) CS [YES]                                    #   4, 1 BurnedInAnnotation
(0042,0010) ST [Informe Imagenes]                       #  16, 1 DocumentTitle
(0042,0012) LO [application/pdf]                        #  16, 1 MIMETypeOfEncapsulatedDocument
*****************************************************

Some of the metadata seems to be right, but I didnt succed on storing the PDF.

I would appreciate any help.

Thank you very much.

vrinda...@j4care.com

unread,
Oct 8, 2020, 3:15:08 AM10/8/20
to dcm4che
Encapsulated Document (0042,0011) tag information is missing in your metadata json

"00420011": {
            "vr": "OB",
            "BulkDataURI": "my_pdf.pdf"
        }

Pela Silveira

unread,
Oct 8, 2020, 8:13:08 AM10/8/20
to dcm4che
Thanks Vrinda!! I didnt now if I have to encode de file in that tag using som sintax.

Thanks for all this work you are doing!

Reply all
Reply to author
Forward
0 new messages