This is a simple console application built for sending files to GDB (VINN or KRITA) at Statistics Sweden. It's main purpose is to show how files can be sent using the M2M-api. Please read the entire documentation at: https://www.scb.se/vinn or https://www.scb.se/krita
The application is pretty simple. Point out your read directory and run the application. When you add a new file to the read directory it will post the file. It uses the directory structure to define the meta data. A certificate is used for authentication. Please contact VINN- or KRITA-support regarding the certificate.
- Install the certificate on the machine. (as the same user running the application)
- Make sure that your
app.config
is correct. (More information in the Configuration-section below) - Create your folder structure. (More information in the Directory structure-section below)
- Build the project.
- Run the project.
- Put the file you wish to send in read directory.
- The application will send the file.
The application is built to run on one server, but support differerent reportees/information providers. This is solved by using a strict directory structure to define which information provider the file belongs to. The structure is defined as such: [read-diretory]\[organisationsnummer]\[referenceperiod]\[fileformat]
In reality it could translate to this: C:\Temp\999000-0045\2022-06-30\V40
When running the application and you put a file in the directory above it will send the file as 999000-0045
and define the fileformat as V40
. If you put the file in C:\Temp
it will use the values in app.config instead.
All necessary configurations should be applied to app.config
, mainly the requestConfiguration
-section. The different parameters is described below:
- ReadDirectory - This is the directory the application will scan for new files (including sub directories)
- DoneDirectory - Sent files will be placed here after a successful post
- CertificateSerialNumber - Serial number for the installed certificate. Note that the application will try to fetch the certificate as the user running the application. Currently as
new X509Store(StoreName.My, StoreLocation.CurrentUser)
. It's convenient when testing, but probably not suitable for production. - BaseUrl - Url for GDB M2M-api. Probably one of these: https://test.m2m.gdb.scb.se/m2m/v2/ https://m2m.gdb.scb.se/m2m/v2/
- PingInterval - Used when you want to ping the api on a regular basis. Convenient when testing, but probably not suitable for production.
- OrganisationNumber - Swedish Organisationnummer for the reportee. Eg. 9990000045. Not needed when using directory structure.
- StatisticalProgram - Statististical program (Sv. undersökning). Either VINN or KRITA. Not needed when using directory structure.
- FileFormat - Type of form. Eg V40, V10, KRITA_MONTHLY. Not needed when using directory structure.
- Version - Version of the form. Eg 1, 3, 5. Usually not needed at all, but the API supports it.
- Referenceperiod - The referenceperiod (month) the file represent. Not needed when using directory structure.
Below are the current APIs URLs to use:
- BaseURL https://test.m2m.gdb.scb.se/m2m/v2/
- Upload File Endpoint https://test.m2m.gdb.scb.se/m2m/v2/file/{segment}/{organisationNumber}/{statisticalProgram}/{referenceperiod}/{fileFormat}/{fileName}/{version?}
- Note that the largest allowed fragment size is 1024*9000 bytes
- Current Status of a file https://test.m2m.gdb.scb.se/m2m/v2/history/{deliveryId} - Here DeliveryId is what is returned when uploading a file.
- Heartbeat https://test.m2m.gdb.scb.se/m2m/v2/heartbeat
- BaseURL https://m2m.gdb.scb.se/m2m/v2/
- Upload File Endpoint https://m2m.gdb.scb.se/m2m/v2/file/{segment}/{organisationNumber}/{statisticalProgram}/{referenceperiod}/{fileFormat}/{fileName}/{version?}
- Note that the largest allowed fragment size is 1024*9000 bytes
- Current Status of a file https://m2m.gdb.scb.se/m2m/v2/history/{deliveryId} - Here DeliveryId is what is returned when uploading a file.
- Heartbeat https://m2m.gdb.scb.se/m2m/v2/heartbeat
Please note that we currently only support the ContentType: multipart/form-data in the http request and that {version?} is optional.
If any APIs aside from version 2 is used, note that as of 2024-11-28 they no longer work and should be switched to V2.
When uploading a file , the file is split into fragments and sent to the API. The API will then merge the fragments and save the file. The largest allowed fragment size is 1024*9000 bytes. Moreover, in order for the system to know when a new file is being sent or if the file is complete, the first fragment should have index 0 and the last fragment must be sent with index = -1. This example solution implements both the chunking and naming the first and last fragments, so you don't have to worry about it. However if you want to create your own solution, you should make sure that these requirements are met.
Tests are are not included in the distributed solution.