.csv file throws error in Import Text

I am trying to read in a .csv file in Grasshopper using Shapediver’s Import Text component. The .csv is saved from Google Sheets.

The component is throwing an error saying the file format is denied, even though text/csv is allowed:

I tried copying the contents of the file into a new file in plain text and save as a .csv, but still got the same error.

Is there currently a working way to import a file exported from Google Sheets into Shapediver?

It simply looks like this:

There is some more info on .csv and MIME types here:

and here:
https://christianwood.net/posts/csv-file-upload-validation/

Who knew such a simple file format could be so complicated.

Btw, I do not currently have and never had any Microsoft Office product on my computer.

I also checked my file at https://mime.ritey.com/ and there it says the file is text/csv:

image

See the Content-Type header of your S3 object here:

$ curl --verbose https://modismo-aws-files.s3.eu-central-1.amazonaws.com/production/monulith.com/test.csv
*   Trying 52.219.47.144:443...
* Connected to modismo-aws-files.s3.eu-central-1.amazonaws.com (52.219.47.144) port 443 (#0)
* ALPN: offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN: server accepted http/1.1
* Server certificate:
*  subject: CN=*.s3.eu-central-1.amazonaws.com
*  start date: Apr 11 00:00:00 2023 GMT
*  expire date: Jan 14 23:59:59 2024 GMT
*  subjectAltName: host "modismo-aws-files.s3.eu-central-1.amazonaws.com" matched cert's "*.s3.eu-central-1.amazonaws.com"
*  issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M01
*  SSL certificate verify ok.
* using HTTP/1.1
> GET /production/monulith.com/test.csv HTTP/1.1
> Host: modismo-aws-files.s3.eu-central-1.amazonaws.com
> User-Agent: curl/7.88.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< x-amz-id-2: +u/p46Kbp3S0Fbq6ddzfzL6k2W0KzSaUTCn1cWnrdUmu+Bi7SupgutAwlQIbt0f23EjoIR5kXgs=
< x-amz-request-id: 4KTK9VX4W3S6340Z
< Date: Fri, 02 Jun 2023 09:08:51 GMT
< Last-Modified: Fri, 02 Jun 2023 08:30:27 GMT
< ETag: "af47916467cda9f5925839c836a42b87"
< x-amz-server-side-encryption: AES256
< x-amz-version-id: tU7EMInWBkiwKI226npoOAKj7OhMkzse
< Accept-Ranges: bytes
< Content-Type: application/vnd.ms-excel
< Server: AmazonS3
< Content-Length: 892
< 
Test1,Test2,Test3
"0,9528462677","0,9985945715","0,1253541054"
"0,2492572506","0,1209077381","0,01505552428"
...

The StackOverflow link that you posted above tells you what you need to do, just set one of the accepted values for the Content-Type header on your S3 object.

This might help: Working with object metadata - Amazon Simple Storage Service

If you want to get knowledgeable about the Content-Type header, I recommend you to read this.

Thanks for the information, that was really helpful. So it turns out that the culprit must be S3 Drive - a software to mount an S3 Bucket as a local drive, which is very convenient.

If I upload the .csv to S3 directly using the web interface, the content-type get’s set correctly and there is no error in Grasshopper.

I will let them know.

Thanks!

Ah, got it, probably S3 drive uses some built-in functionality of Windows to detect the Content-Type.

1 Like

I wrote with n Software and apparently they have their own content-type settings and use application/vnd.ms-excel as their default. Let’s hope they see the light and change it.

But now I have another question:

We have a file upload field in Grasshopper an input the .csv file from the S3 bucket as the default. But you can also upload a file in Shapediver:

But once you upload it, and go out of edit mode and back in, no file is shown. I believe that any file uploaded get’s put on your amazon S3 and the file URL replaced.

If I cannot see the file name there a) how do I know what file is set and b) how can I not use the uploaded file, but use the default file specified in Grasshopper? Basically if I upload a file once I can never use the fallback now, right?

I think it should always show the file name at least. This will be the same regardless of where the file is saved. Then I can tell what the file is and if I delete the filename it would also delete the file and use the fallback. Doesn’t that make more sense? Or what is the reason for not showing a file name there?

One more thing I noticed is that if you only use the default URI in the Import Text component in Grasshopper, you specify a URL to the file. But if I change the file in AmazonS3 it does not update in the Shapediver model.

Can it be, that you are caching the file or putting it in your own S3 storage even for the default URL? So if I update the file, but the URL is the same as before I cannot see the changes?

In that case I could only update the file in Shapediver really!?

Okay, I figured it out. If you have a default URL set in the Import Text component, then it will use that file as the fallback.

You can stop using a file, by clicking the little paperclip in Shapediver and then cancel out of the file dialog.

But it will fallback to the file specified in the URL at the time it was uploaded (presumably because it got cached then). So I guess there is no way to update the fallback once you have uploaded a model??

In that case we always have to update the file through Shapediver.

Precisely. See Import Text

Technical details about File parameters: File parameters (inputs)

Please read this:

You can also append a random query string parameter to your default URL, that way you can force a new computation.

Example: https://host.name.com/file.ending?v=SOME_RANDOM_STRING

Agreed that there is potential to improve the UI for File parameters. It does not become clear how to unselect a file set as a default value. We do not store the filename, i.e. if you set a default file in edit mode, the filename will not be shown on the model view page. Reason: When you select a file, it gets uploaded and an id is assigned to it. Only this id of the uploaded file is stored as the parameter’s default value, see technical details.

1 Like