title: [aws-sdk-cpp][s3] Downloading binary file with getObject
body: <p>I've being tried to write some codes to download binary files from AWS S3 server.</p>
  
  <p>I wrote that code right below and It looks like okay about ~200MB binary files, so I thought it worked.</p>
  
  <p>but for big files like 200MB~, it would be downloaded but only front part of files.</p>
  
  <p>for example, a video file (1.2GB) downloaded only front part(460MB ~ 700MB).</p>
  
  <p>Why this can be happened? It's about ofstream features?</p>
  
  <pre><code>// 3. file download from s3
  {
      string strTargetPath = hThis-&gt;m_strTargetPath;
      Aws::SDKOptions options;
      options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;
      Aws::InitAPI(options);
      {
          // Download from s3 using GetObject
  
          char *bucket_name = "mybucket";
          std::string key_name = strTargetPath;
  
          Aws::Client::ClientConfiguration clientConfig;
          clientConfig.region = "ap-northeast-2";
  
          //Aws::S3::S3Client s3_client;
          std::unique_ptr&lt; Aws::S3::S3Client &gt; s3_client(new Aws::S3::S3Client(clientConfig));
          Aws::S3::Model::GetObjectRequest object_request;
          object_request.WithBucket(bucket_name).WithKey(key_name.c_str());
  
          // parse file name from path
          string str_arr[1000];
          int str_cnt = 0;
  
          char *str_buff = new char[1000];
          strcpy(str_buff, strTargetPath.c_str());
  
          char *tok = strtok(str_buff, "/");
          while (tok != nullptr) {
              str_arr[str_cnt++] = string(tok);
              tok = strtok(nullptr, "/");
          }
  
          string fileName = str_arr[str_cnt - 1];
  
          auto get_object_outcome = s3_client.get()-&gt;GetObject(object_request);
  
          if (get_object_outcome.IsSuccess())
          {
              Aws::OFStream local_file;
              std::string strFileName = fileName;
              hThis-&gt;m_origFileNameString = strFileName;
              hThis-&gt;m_origFileName = strFileName.c_str();
  
              // Writing file downloaded
              local_file.open(hThis-&gt;m_origFileName, std::ios::out | std::ios::binary);
              local_file &lt;&lt; get_object_outcome.GetResult().GetBody().rdbuf();
              hThis-&gt;Logger(CPrePackagerDlg::currentDateTime() + "download is done\n");
  
              TCHAR programpath[_MAX_PATH];
              GetCurrentDirectory(_MAX_PATH, programpath);
              hThis-&gt;m_valOriginFolderPath.Format(_T("%s\\"), programpath);
              hThis-&gt;m_valOriginFolderPath += hThis-&gt;m_origFileName;
          }
          else
          {
              hThis-&gt;Logger(CPrePackagerDlg::currentDateTime() + "s3 download error: " +
                  get_object_outcome.GetError().GetExceptionName() + " " +
                  get_object_outcome.GetError().GetMessage() + "\n");
              hThis-&gt;runSignal = CPrePackagerDlg::RunSignal::STAT_RUN_STOP;
          }
  
  
      }
      Aws::ShutdownAPI(options);
  
  }
  </code></pre>