{"record":{"id":"46fa53c9a4210575","repo":"carrierwaveuploader/carrierwave","slug":"could-not-download-file-no-content","errorCode":null,"errorMessage":"could not download file: No Content","messagePattern":"could not download file: No Content","errorType":"exception","errorClass":"CarrierWave::DownloadError","httpStatus":null,"severity":"error","filePath":"lib/carrierwave/downloader/remote_file.rb","lineNumber":12,"sourceCode":"module CarrierWave\n  module Downloader\n    class RemoteFile\n      attr_reader :file, :uri\n\n      def initialize(file)\n        case file\n        when String\n          @file = StringIO.new(file)\n        when Net::HTTPResponse\n          body = file.body\n          raise CarrierWave::DownloadError, 'could not download file: No Content' if body.nil?\n\n          @file = StringIO.new(body)\n          @content_type = file.content_type\n          @headers = file\n          @uri = file.uri\n        else\n          @file = file\n          @content_type = file.content_type\n          @headers = file.meta\n          @uri = file.base_uri\n        end\n      end\n\n      def content_type\n        @content_type || 'application/octet-stream'\n      end\n\n      def headers","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/carrierwaveuploader/carrierwave/blob/b5f0abe10ecf6500309fc83e0e8969cf57ba690e/lib/carrierwave/downloader/remote_file.rb#L1-L30","documentation":"Raised as CarrierWave::DownloadError by CarrierWave::Downloader::RemoteFile#initialize when the wrapped Net::HTTPResponse has a nil body. The downloader only guards HTTP status via response.value; some 2xx responses (204 No Content, 304 Not Modified) succeed that check yet legally carry no body, and RemoteFile refuses to wrap a bodyless response.","triggerScenarios":"uploader.download!('http://...') where the endpoint answers 204 No Content or 304 Not Modified (e.g. a cache hit, a HEAD-ish endpoint, or an API route returning empty 2xx instead of the file bytes). The status passes response.value (it is 2xx) but file.body is nil, so this error fires.","commonSituations":"Pointing the remote-file URL at an API endpoint or CDN edge that returns an empty 2xx under some conditions; a misconfigured server returning 204 for what should be a file download; broken presigned URLs that redirect to an empty response.","solutions":["Confirm what the URL actually returns from the app host: curl -i <url> and inspect status plus Content-Length","Fix the remote endpoint to serve the real file bytes with 200 and a body","If empty responses are expected, rescue CarrierWave::DownloadError and treat it as an invalid URL"],"exampleFix":"# before\nuploader.download! url # raises 'could not download file: No Content'\n\n# after\nbegin\n  uploader.download! url\nrescue CarrierWave::DownloadError => e\n  raise if e.message !~ /No Content/\n  errors.add(:url, 'returned no content')\nend","handlingStrategy":"validation","validationCode":"require 'net/http'\n\ndef url_serves_body?(url)\n  uri = URI.parse(url)\n  res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') { |http| http.get(uri.request_uri) }\n  res.is_a?(Net::HTTPSuccess) && !res.body.nil? && !res.body.empty?\nrescue StandardError\n  false\nend","typeGuard":null,"tryCatchPattern":"begin\n  uploader.download!(url)\nrescue CarrierWave::DownloadError => e\n  if e.message =~ /No Content/\n    errors.add(:url, 'returned an empty response')\n  else\n    raise\n  end\nend","preventionTips":["Preflight download URLs with a GET/HEAD and require a non-empty body (or Content-Length > 0)","Treat endpoints that can legitimately answer 204 as invalid sources for remote-file download"],"tags":["carrierwave","download","http-204","empty-body","remote-file"],"backgroundTag":"empty-response-body","analyzedSha":"b5f0abe10ecf6500309fc83e0e8969cf57ba690e","analyzedAt":"2026-08-21T18:07:27.715Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}