@@ -46,6 +46,7 @@ public struct LogFileReference
4646 {
4747 public string path ;
4848 public bool removeAfterUpload ;
49+ public Logger logger ; // Optional: if set, use logger.ReadLogFileBytes() instead of path
4950 }
5051
5152 public struct ScreenshotFileReference
@@ -381,8 +382,25 @@ private IEnumerator PostScreenshot(ScreenshotFileReference screenshot)
381382
382383 private IEnumerator PostLogFile ( LogFileReference logFile )
383384 {
384- if ( File . Exists ( logFile . path ) )
385+ if ( logFile . logger != null )
385386 {
387+ // Use logger's safe read method to avoid sharing violations
388+ Debug . Log ( "Reading BetaHub log file safely using Logger instance" ) ;
389+ byte [ ] fileData = logFile . logger . ReadLogFileBytes ( ) ;
390+
391+ if ( fileData != null )
392+ {
393+ string fileName = Path . GetFileName ( logFile . logger . LogPath ) ?? "BH_Player.log" ;
394+ yield return UploadStringAsFile ( "log_files" , "log_file[file]" , fileData , fileName , "text/plain" ) ;
395+ }
396+ else
397+ {
398+ Debug . LogError ( "Failed to read log file data from Logger instance" ) ;
399+ }
400+ }
401+ else if ( File . Exists ( logFile . path ) )
402+ {
403+ // Original file path logic
386404 yield return UploadFile ( "log_files" , "log_file[file]" , logFile . path , "text/plain" ) ;
387405
388406 if ( logFile . removeAfterUpload )
@@ -433,6 +451,37 @@ private IEnumerator UploadFile(string endpoint, string fieldName, string filePat
433451 }
434452 }
435453
454+ private IEnumerator UploadStringAsFile ( string endpoint , string fieldName , byte [ ] fileData , string fileName , string contentType )
455+ {
456+ if ( fileData == null )
457+ {
458+ Debug . LogError ( $ "Cannot upload { fileName } : file data is null") ;
459+ yield break ;
460+ }
461+
462+ WWWForm form = new WWWForm ( ) ;
463+ form . AddBinaryData ( fieldName , fileData , fileName , contentType ) ;
464+
465+ string url = $ "{ _betahubEndpoint } projects/{ _projectId } /issues/g-{ Id } /{ endpoint } ";
466+ using ( UnityWebRequest www = UnityWebRequest . Post ( url , form ) )
467+ {
468+ www . SetRequestHeader ( "Authorization" , "Bearer " + _updateIssueAuthToken ) ;
469+ www . SetRequestHeader ( "BetaHub-Project-ID" , _projectId ) ;
470+ www . SetRequestHeader ( "Accept" , "application/json" ) ;
471+
472+ yield return www . SendWebRequest ( ) ;
473+
474+ if ( www . result != UnityWebRequest . Result . Success )
475+ {
476+ Debug . LogError ( $ "Error uploading { fileName } : { www . error } ") ;
477+ }
478+ else
479+ {
480+ Debug . Log ( $ "{ fileName } uploaded successfully!") ;
481+ }
482+ }
483+ }
484+
436485 private IEnumerator PublishNow ( )
437486 {
438487 // Ensure we have valid parameters before proceeding
0 commit comments