File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
modules/openapi-generator/src/main/resources/ruby-client Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -71,8 +71,17 @@ module {{moduleName}}
71
71
{ {/isFaraday} }
72
72
{ {#isFaraday} }
73
73
if return_type == 'File'
74
- @tempfile = Tempfile.open('download-', @config.temp_folder_path, encoding: body.encoding)
75
- @tempfile.write(@stream.join.force_encoding(body.encoding))
74
+ content_disposition = response.headers['Content-Disposition']
75
+ if content_disposition && content_disposition =~ /filename=/i
76
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
77
+ prefix = sanitize_filename(filename)
78
+ else
79
+ prefix = 'download-'
80
+ end
81
+ prefix = prefix + '-' unless prefix.end_with?('-')
82
+ encoding = body.encoding
83
+ @tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
84
+ @tempfile.write(@stream.join.force_encoding(encoding))
76
85
@tempfile.close
77
86
@config.logger.info "Temp file written to #{ @tempfile.path} , please copy the file to a proper folder "\
78
87
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
You can’t perform that action at this time.
0 commit comments